If I have a parent that sets a state and passes it to a child, how can I change the state of the parent FROM the child?
// parent
this.state = {
status: 'doing...'
}
// child render
<div>{this.props.state.status}</div>
// child function triggered by an onClick
update = () => this.setState(status: 'finished');
Something like this doesn't work
// parent
this.state = {
status: this.props.state.status
}
// or child
this.props.setState(status: 'finished');
// or child
getDerivedStateFromProps(nextProps) {
console.log('I'm never executed)
this.setState({ status: nextProps.state.status});
}