我正在尝试弄清楚如何基于布尔值呈现组件。但用户也将有权改变布尔值,我需要的应用程序来实时更新。
为了简单起见,目前我仅尝试呈现一些文本:
const deposit = <Text>deposit</Text>
const noDeposit = <Text>noDeposit</Text>
这是我想要渲染的视图:
<View>
{this.props.depositRequired ? deposit : noDeposit}
</View>
它可以在应用程序第一次启动时显示其中的一个。但它从来不会更新,我有点不知道该怎么做。任何帮助都是非常感谢的!
发布于 2019-05-30 08:37:24
尝试使用生命周期方法接收称为componentWillReceiveProps
的道具来进行组件更新。像这样实现它:
componentWillReceiveProps(nextProps){
if(nextProps.depositRequired !== this.props.depositRequired){
// just call to update the component
this.setState({})
}
}
https://stackoverflow.com/questions/56370111
复制相似问题