Javascript 基于状态中的布尔值的React渲染:三元不工作
React-Dev工具向我显示状态正在成功更改,但是正确的组件没有呈现 以下是切换状态的按钮内的三元值:Javascript 基于状态中的布尔值的React渲染:三元不工作,javascript,reactjs,state,conditional-operator,Javascript,Reactjs,State,Conditional Operator,React-Dev工具向我显示状态正在成功更改,但是正确的组件没有呈现 以下是切换状态的按钮内的三元值: return ( <div> <div>{questionBlocks}</div> <button className="advanced-options" onClick={this.toggleAdvanced}> {this.state.advancedText} <
return (
<div>
<div>{questionBlocks}</div>
<button className="advanced-options" onClick={this.toggleAdvanced}>
{this.state.advancedText}
<span>
{this.showAdvanced ? <ExpandLessIcon /> : <ExpandMoreIcon />}
</span>
</button>
</div>
);
除其他外,我们进行了研究,但没有成功。问题可能就在这里
<span>
{this.showAdvanced ? <ExpandLessIcon /> : <ExpandMoreIcon />}
</span>
{this.showAdvanced?:}
您正在使用
this.showAdvanced
,但它应该是this.state.showAdvanced问题可能就在这里
<span>
{this.showAdvanced ? <ExpandLessIcon /> : <ExpandMoreIcon />}
</span>
{this.showAdvanced?:}
您正在使用this.showAdvanced
,但它应该是this.state.showAdvanced您在三元结构中缺少state
。它应该是this.state.showAdvanced
,而不是this.showAdvanced
您在三元结构中缺少状态
。它应该是this.state.showAdvanced
,而不是this.showAdvanced