在我的项目中,我有一个按钮,我想使用状态禁用它。
<Button
color='success'
onClick={this.changeForm}
block
disabled
>
LOGIN
</Button>
我正在使用Reactstrap。我在state
中设置了一个flag
值。如果flag
设置为TRUE
,我想禁用该按钮。所以,我想出了这个代码:
<Button
color='success'
onClick={this.changeForm}
block
{this.state.flag && 'disabled'}
>
LOGIN
</Button>
我越来越Syntax Error
.我知道这是一个不正确的语法,那么我如何才能实现我想要的功能?
disabled
是Button
的道具。因此:
<Button
color='success'
onClick={this.changeForm}
disabled={this.state.flag}
>
LOGIN
</Button>