Reputation:
const GrandParent = (props) => {
const close = () => {
console.log("Pressed");
}
return (<Parent func={() => close()} />)
}
const Parent = (props) => {
return (<Child onPress={ /**call close function from GrandParent component*/} />)
}
const Child = (props) => {
return (<Button onPress={() => props.onPress} />)
}
I was able to call GrandParent
s component method from Parent
component using the props
, but I want to call it from the Child
component and I can't seem to do it.
Upvotes: 1
Views: 92
Reputation: 11
const GrandParent = (props) => {
const close = () => {
console.log("Pressed");
}
return (<Parent func={() => close()} />)
}
const Parent = (props) => {
return (<Child onPress={()=> props.func()} fun1={()=> props.func()}/>)
}
const Child = (props) => {
return (<Button onPress={()=> props.func1()} />)
}
Upvotes: 1
Reputation: 11456
It should work like this:
const GrandParent = (props) => {
const close = () => {
console.log("Pressed")
}
return (<Parent func={() => close()} />)
}
const Parent = (props) => {
return (<Child func={() => props.func()} />)
}
const Child = (props) => {
return (<Button onPress={() => props.func()} />)
}
Upvotes: 0