react-native - React Native 不会重新运行 componentDidMount

标签 react-native react-navigation

我有一个可触摸项目的列表,单击其中任何一个都会将您带到详细信息屏幕。

详细信息屏幕在 componentWillMount() 中从服务器获取数据。

当我单击第一个项目时,详细信息屏幕将显示正确的数据。然后返回列表并单击另一个项目,详细信息屏幕将再次显示第一个项目的数据。

最佳答案

您必须使用componentDidUpdate并从那里执行操作。

componentDidUpdate(prevProps) {
   if(prevProps!==this.props){
     //do the same as your componentDidMount
  }
}

componentDidMount 仅在第一次渲染特定组件时触发,要获取必须使用 componentDidUpdate 的新数据

关于react-native - React Native 不会重新运行 componentDidMount,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56977993/

相关文章:

react-native - react-navigation:从标题中的按钮导航到不同的屏幕

javascript - 在 react 导航中传递 id 与传递对象

react-native - react native 链接邮件api支持主题,正文?

React-native,动态渲染按钮点击

ios - [RN][IOS]是否可以将 React Native RCTLinking 与 RNFirebase 动态链接结合使用?

react-native - React Navigation RedirectUrl 实现

react-native - React Native - 在导航到/从包含嵌入在其自己的 WebView 中的多条推文的页面导航后取消引用空指针

android - 如何使用 React Native 从文件系统检索文件,以转换为 base64 并以 JSON 格式发布 http?

android - 未定义不是 React Native 项目中的函数

react-native - 两种颜色的背景 - React Native