0

I have two siblings class components and I am trying to call a function with arguments that resides in the PMtoXX from the XYtoPM. I am stuck of how to pass on the parameters and invoke the function. I get the error that the plot_PMSegment expected one argument.

` PMtoXY.tsx

class PMtoXY extends Component<IProps> {
----
plot_PMSegment = (beg_routeid, end_routeid) => {
-----
}
}

export default PMtoXY;

and I have this sibling component that I am trying to call the PMtoXY function from it.

XYtoPM.tsx `


class XYtoPM extends Component<IProps> {

import PMtoXY from "./PMtoXY";
----
-----
new plot_PMSegment(therouteid, theend_routeid)
-----
export default XYtoPM
2
  • Since React has uni-directional, top to bottom approach, straightforward solution is not possible.. Use can use either the Parent Component of both siblings or use Context API instead Commented Dec 15, 2022 at 4:10
  • A quick read could help you .. patrickdesjardins.com/blog/… Commented Dec 15, 2022 at 4:11

1 Answer 1

1

I found my answer from one of the suggestions (not the answer) provided on this posting: How to call a function from another class in React-Native?

The suggestion was: "You dont initiate your class, to solve this you need to change the B.abc() to new B().abc();"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.