React: setting the disabled attribute based on a state
问题 I'd like to set the disabled attribute on a Button based on component's state, something like this: render() { return ( <button type="button" {this.state.submitting ? 'disabled' : ''} onClick={ this.handleSubmit }>Submit</button> ); } At the moment I get an Unexpected token error on the opening {, what am I missing? 回答1: You can set disabled property through boolean value, like this <button type="button" disabled={this.state.submitting} onClick={this.handleSubmit} > Submit </button> Example