Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native get parent of components

Tags:

react-native

I'm new to React Native and I have a component inside a component.

I need to access a function of the parent from the child component. How do I access the parent, e.g. something like this.parentNode.myFunc(); from the child? (of course, without passing it as a prop down the whole view hierarchy)

like image 520
Can Poyrazoğlu Avatar asked Jul 21 '26 04:07

Can Poyrazoğlu


1 Answers

Send to child component as props. Like that:

<ChildComponent myProp={this.myFunc} />

and then, you can call the function this.props.myProp()

like image 141
akcoban Avatar answered Jul 22 '26 19:07

akcoban