Please be lenient, because I am an amateur. Situation: When rendering a component1, component2 is used in which the property is transferred. The state of component2 changes in its processor. It is necessary to fix the change in state of component 2 and take this into account in component 1.
var Component1 = React.createClass({ getInitialState(){ return{ total: 0 } }, render(){ const total = this.state.total; return <Component2 total={total} /> } }); var Component2 = React.createClass({ getInitialState(){ return{ total: this.props.total } }, handleClick(){ var total = this.state.total + 1; this.setState({total: total}); }, render(){ const total = this.state.total; return <div onClick={this.handleClick}>{total}</div> } }); - Question1: How do I change the total state in Component1 from Component2?
- Question2: (in case the first option is completely absurd): which option would you suggest to take into account changes in the state of another component (do you need to transfer the property to the component chain by order - if yes, how to get feedback)?