React native 如何在React Native中编写等价的IF/ELSE语句?

React native 如何在React Native中编写等价的IF/ELSE语句?,react-native,React Native,我想在React Native中编写与此等效的代码: if(response){ if(status ==='ERROR'){ return 'Error' }else{ return 'Response Returned' } } 我尝试了以下方法: { Object.keys(this.props.myStore.response).length !==0 ? (this.props.myStore.status ===

我想在React Native中编写与此等效的代码:

if(response){
    if(status ==='ERROR'){
        return 'Error'
    }else{
        return 'Response Returned'
    }
}

我尝试了以下方法:

{
  Object.keys(this.props.myStore.response).length !==0  ? 
  (this.props.myStore.status ==='ERROR') ? 
    <Text>error</Text> : 
    <Text>Response Returned</Text>
}
对于这些代码,我会出错,我是一个新的本地反应者,但我尝试了上述代码的变体,但仍然会出错。对于将此代码块改进为最佳实践的任何进一步建议,我们将不胜感激。

您应该尝试此方法


状态=='错误'?'错误“:“Response Returned”终于让它工作了,代码如下:

{
      Object.keys(this.props.myStore.response).length ===0 ?
      null : 
      this.props.myStore.status ==='ERROR' ? 
        <Text>error</Text> : 
        <Text>Response Returned</Text>
    }

您介意告诉我这些错误消息是怎么说的吗?您的代码的问题是您缺少外部三元运算符中的“:”。