Hello I have a problem with calling a function passed as prop at the child component. Im trying to replicate my code with only the relevant lines of code:
class Parent extends Component {
constructor(props) {
super(props)
this.press = this.press.bind(this)
}
press(param) {
console.log(param)
}
renderItem = ({item}) => (
<Child item={item} press={this.press} />
)
render() {
return (
<FlatList renderItem={this.renderItem} />
)
}
}
class Child extends PureComponent {
handlePress(param) {
// do some stuff
// call parent function
this.props.press(param)
}
render() {
const { id } = item
return <Button onPress={() => this.handlePress(id)} />
}
}
At the moment when pressing the button nothing happens, I got this already working with something like this:
<Child press={(param) => this.press(param)} />
however this causes performance issues.
How can I make this work ?
After a while of testing I came to this solution: