Javascript 基于状态中的布尔值的React渲染:三元不工作

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} <

React-Dev工具向我显示状态正在成功更改,但是正确的组件没有呈现

以下是切换状态的按钮内的三元值:

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