我想使用三元运算符根据某些状态条件渲染两个按钮,以避免代码重复。
我想做什么?
我有两个按钮 Cancel 和 Start 基于 state value load_cancel
。如果单击 Cancel 按钮load_cancel
设置为true
,当load_cancel
设置为false
Start 按钮时显示。所以我在render
方法中有这样的东西
{props.item_id && this.props.load_cancel &&
<button onClick=
{this.props.handle_load_start}>start</button>}
{props.item_id && !this.props.load_cancel &&
<button onClick={this.props.handle_load_cancel}>Cancel</button>}
如何使用三元运算符做同样的事情?
谢谢。