how to pass the whole state into child component code example
Example 1: pass setstate to child
class ChildExt extends React.Component {
render() {
return (<div><button onClick={() => this.props.handleForUpdate('someNewVar')}>Push me</button></div>
)}
}
class ParentExt extends React.Component {
constructor(props){
super(props);
this.state = {lol: false }
}
handleForUpdate(someArg){
this.setState({lol: true});
console.log(someArg);
}
render() {
return (<ChildExt handleForUpdate={this.handleForUpdate.bind(this)} />)
}
}
Example 2: how to pass state from parent to child in react
class SomeParentComponent extends React.Component {
constructor(props) {
super(props);
this.state = {color: 'red'};
}
render() {
return <SomeChildComponent color={this.state.color} />;
}
}