The following answer was a quick and good solution for updating the parent component when the child’s state has changed.
class Parent extends React.Component { constructor(props) { super(props) this.handler = this.handler.bind(this) } handler(e) { e.preventDefault() this.setState({ someVar: someValue }) } render() { return <Child handler = {this.handler} /> } } class Child extendes React.Component { render() { return <Button onClick = {this.props.handler}/ > } }
Sources:
- http://stackoverflow.com/questions/35537229/how-to-update-parents-state-in-react
- http://stackoverflow.com/users/3103108/woolywhale