为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 React.js 中添加条件

如何在 React.js 中添加条件

慕码人2483693 2021-12-12 09:42:30
如果两个条件为真,我想显示工具提示。  <LikelihoodIndicatorRefi likelihood={ props.props.approvalChance_NewLoan } >        {console.log(props.props.approvalChance_NewLoan === 'Less Likely' && props.props.approvalChance_Combined === 'Less Likely')}        {(props.props.approvalChance_NewLoan === 'Less Likely' && props.props.approvalChance_Combined === 'Less Likely' &&          <SmartTooltip wrapperCssClass="option-detail-tooltip" ctaLabel="How do I increase my chances?">            <h3>Less Likely</h3>            <p>              Want to improve your chnace of getting this loan? &nbsp;Try increasing the time to pay it back over.Or you could try asking for less money.            </p>          </SmartTooltip>)}        </LikelihoodIndicatorRefi>  <LikelihoodIndicatorRefi likelihood={ props.props.approvalChance_NewLoan } >        {console.log(props.props.approvalChance_NewLoan === 'Less Likely' && props.props.approvalChance_Combined === 'Less Likely')}        {(props.props.approvalChance_NewLoan === 'Less Likely' && props.props.approvalChance_Combined === 'Less Likely' &&          <SmartTooltip wrapperCssClass="option-detail-tooltip" ctaLabel="How do I increase my chances?">            <h3>Less Likely</h3>            <p>              Want to improve your chnace of getting this loan? &nbsp;Try increasing the time to pay it back over.Or you could try asking for less money.            </p>          </SmartTooltip>)}        </LikelihoodIndicatorRefi>
查看完整描述

2 回答

?
青春有我

TA贡献1784条经验 获得超8个赞

尝试


  {(props.props.approvalChance_NewLoan === 'Less Likely' && 

   props.props.approvalChance_Combined === 'Less Likely' ?

      <SmartTooltip wrapperCssClass="option-detail-tooltip" ctaLabel="How do I increase my chances?">

        <h3>Less Likely</h3>

        <p>

          Want to improve your chnace of getting this loan? &nbsp;Try increasing the time to pay it back over.Or you could try asking for less money.

        </p>

      </SmartTooltip>) : null}


查看完整回答
反对 回复 2021-12-12
?
墨色风雨

TA贡献1853条经验 获得超6个赞

简单地链接&&表达式,如果之前的所有表达式都为真,它总是会计算到最后一个表达式。所以bool && bool && <Component />将足以显示它。如果您将它作为 JSX 树中的第一个元素,那么您应该<></>在条件周围添加React.Fragment 以获得有效的根元素。


查看完整回答
反对 回复 2021-12-12
  • 2 回答
  • 0 关注
  • 183 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信