Reactjs 有条件地应用样式进行反应/重做
在我的Reactjs 有条件地应用样式进行反应/重做,reactjs,redux,react-redux,Reactjs,Redux,React Redux,在我的React&Redux应用程序中,我试图根据Redux返回的状态显示/隐藏div。这是我的密码: <div className="notify-success" style={{ ({this.props.terms}) ? "" : "display: 'none'" }} > Saved successfully! </div> 成功保存! 但这对我不起作用,而是抛出了一个错误 将条件设置为值,使用以下命令: style={
React&Redux
应用程序中,我试图根据Redux
返回的状态显示/隐藏div
。这是我的密码:
<div
className="notify-success"
style={{ ({this.props.terms}) ? "" : "display: 'none'" }}
>
Saved successfully!
</div>
成功保存!
但这对我不起作用,而是抛出了一个错误 将条件设置为值,使用以下命令:
style={{'display': this.props.terms ? "" : 'none' }}
尝试使用类名进行更好的练习
classNames('foo', 'bar'); // => 'foo bar'
classNames('foo', { bar: true }); // => 'foo bar'
classNames({ 'foo-bar': true }); // => 'foo-bar'
classNames({ 'foo-bar': false }); // => ''
classNames({ foo: true }, { bar: true }); // => 'foo bar'
classNames({ foo: true, bar: true }); // => 'foo bar'
请参阅此链接
这将返回生成的类名,您可以将其放入render方法中,当变量更改时,它将根据需要进行更新。如果不需要,请不要渲染
:
render() {
return { this.props.terms ?
<div className="notify-success">
Saved successfully!
</div> : null
}
}
render(){
返回{this.props.terms?
成功保存!
:null
}
}