I have a function that comes from the parent, down to the child of the child in the component hierarchy. This is usually not a big deal, but I need to get the parameter from the child. I am currently getting this error message: Unavailable (in promise) TypeError: this.props.myFunction is not a function.
Here is a sample code for what I am doing:
class SomeComponent extends Component{ constructor(props){ super(props); //does whatever stuff this.myFunction = this.myFunction.bind(this); } //(only applicable to raw and normal forms) myFunction(param){ console.log('do something: ', param); } render(){ return (<div><ChildComponent1 myFunction={()=>this.myFunction()}/></div>) } } class ChildComponent1{ render(){ return (<div><ChildComponent2 myFunction={()=>this.props.myFunction()}/></div>) } } class ChildComponent2{ render(){ return (<Button onClick={()=>this.props.myFunction(param)}>SomeButton</Button>) } }
So, just for this: I pass myFunction as a support from SomeComponent up to ChildComponent2, in which I want it to be called whenever the button is pressed and the parameters are passed from ChildComponent2.
Thanks!
source share