Want to set the disabled attribute based on a state in React? You can set disabled property through boolean value, like below example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | var Component = React.createClass({ getInitialState() { return { submitting: true } }, handleSubmit() { }, toggleButton() { this.setState({ submitting: !this.state.submitting }) }, render() { console.log(this.state.submitting); return (<div> <button type="button" disabled={this.state.submitting} onClick={ this.handleSubmit }>Submit</button> <button onClick={ this.toggleButton }>Toggle</button> </div>); } }); ReactDOM.render( <Component />, document.getElementById('container') ); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.