Reactjs 在React Native+;中进行条件渲染的正确方法是什么;雷杜?
当我在React with Redux中制作应用程序时,我会在Render中执行以下操作:Reactjs 在React Native+;中进行条件渲染的正确方法是什么;雷杜?,reactjs,react-native,redux,Reactjs,React Native,Redux,当我在React with Redux中制作应用程序时,我会在Render中执行以下操作: {!this.state.modalShown?:} 但是,它在Redux中似乎不起作用。这是在App.js组件中,我订阅了商店,这个JSX包装在提供者中 {store.getState().currentRestaurantCode===''||store.getState().currentRestaurantCode==='Bad Request' ?<View> Some eleme
{!this.state.modalShown?:}
但是,它在Redux中似乎不起作用。这是在App.js组件中,我订阅了商店,这个JSX包装在提供者中
{store.getState().currentRestaurantCode===''||store.getState().currentRestaurantCode==='Bad Request'
?<View> Some elements </View>
:<View> Some other elements </View>
}
{store.getState().currentRestaurantCode==''| | store.getState().currentRestaurantCode====''错误请求'
?一些要素
:一些其他元素
}
但是,它不起作用。我做错什么了吗?这里是Redux的新手。我认为多重条件造成了这个问题。这不是重复的问题 试试这个
const isRestaurantCodeEmpty = store.getState().currentRestaurantCode===''||store.getState().currentRestaurantCode==='Bad Request';
....
{isRestaurantCodeEmpty
?<View> Some elements </View>
:<View> Some other elements </View>
}
const isRestaurantCode=store.getState().currentRestaurantCode===''| | store.getState().currentRestaurantCode===='Bad Request';
....
{IsrestaurantDeempty
?一些要素
:一些其他元素
}
您应该调用您的操作,并通过还原程序(您应该创建操作和还原程序),然后通过connect获取数据,并从MapStateTrops函数将其传递到表单。似乎您没有执行这些操作。请尝试逻辑和&&
,而不是|
。请添加更多信息。首先你应该提到的是你得到了什么作为输出。另外,您是否调试/检查了store.getState().currentRestaurantCode
的值?如果未保持所需的值,则可能减速器未正确更新。否则语法看起来是正确的。这是执行条件代码的正确方法,但是您可以使用This.props.state
来检查条件是否正确,而不是执行store.getState()
。