首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >react-native中的实时条件渲染

react-native中的实时条件渲染
EN

Stack Overflow用户
提问于 2019-05-30 08:19:33
回答 1查看 102关注 0票数 0

我正在尝试弄清楚如何基于布尔值呈现组件。但用户也将有权改变布尔值,我需要的应用程序来实时更新。

为了简单起见,目前我仅尝试呈现一些文本:

代码语言:javascript
复制
const deposit = <Text>deposit</Text>
const noDeposit = <Text>noDeposit</Text>

这是我想要渲染的视图:

代码语言:javascript
复制
<View>
  {this.props.depositRequired ? deposit : noDeposit}
</View>

它可以在应用程序第一次启动时显示其中的一个。但它从来不会更新,我有点不知道该怎么做。任何帮助都是非常感谢的!

EN

回答 1

Stack Overflow用户

发布于 2019-05-30 08:37:24

尝试使用生命周期方法接收称为componentWillReceiveProps的道具来进行组件更新。像这样实现它:

代码语言:javascript
复制
  componentWillReceiveProps(nextProps){
  if(nextProps.depositRequired !== this.props.depositRequired){
    // just call to update the component
    this.setState({})
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56370111

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档