I am new to the reactor. When changing state after setState({isDisabled: this.props.isDisabled})
I still get the old value in this.state.isDisabled
. What am I doing wrong?
const ButtonRegister = React.createClass({ componentWillReceiveProps() { if (this.props.isDisabled !== undefined) { this.setState({isDisabled: this.props.isDisabled}); console.log('props vs state: ', this.props.isDisabled, this.state.isDisabled); } }, render() { return ( <button disabled={this.props.isDisabled} << 1 disabled={this.state.isDisabled} << 2 type="button">Registration</button> ) } });
Those. console.log()
shows different values for state
and props
, and the button, if you leave the << 2 option in its state, is late.
In other words, I wanted to intercept props.isDisabled
and force it into state
. But after setState()
control does not redraw. Or am I somehow changing the state
?