代码之家  ›  专栏  ›  技术社区  ›  tesicg

如何在React中检查对象是否为空或未定义?

  •  0
  • tesicg  · 技术社区  · 8 年前

    React :

    {financialPerformance && (
      financialPerformance.isConfirmed ? (
        <L.Text txtGray>Confirmed</L.Text>
      ) : (
        <L.Text txtGray>Not Confirmed</L.Text>
      )
    )}
    

    financialPerformance 本身也是为了 null undefined 和展示 “未确认” 财务表现 反对。

    {financialPerformance && (
    

    我怎样才能在上面的街区内或街区外做到这一点?

    1 回复  |  直到 8 年前
        1
  •  6
  •   falinsky Giri Dharan    8 年前

    由于 null 和 undefined 将被评估为 false

    {
      financialPerformance && financialPerformance.isConfirmed ? (
        <L.Text txtGray>Confirmed</L.Text>
      ) : (
        <L.Text txtGray>Not Confirmed</L.Text>
      )
    }