【问题标题】:React Native: what lifecycle should I look for when I want to refresh ListView whenever I navigate back to it?React Native:当我想要刷新 ListView 时,我应该寻找什么生命周期?
【发布时间】:2016-04-28 23:54:35
【问题描述】:

很像这里的官方教程https://facebook.github.io/react-native/docs/tutorial.html

我在ComponentDidMount 中调用了fetchData 方法,但根据thisComponentDidMount 只会在组件初始渲染后调用一次。那么我是否应该在每次导航回此 ListView 之前调用相同的 fetchData,并将更新的数据作为道具传递给 ListView,然后在 componentDidUpdate 中相应地更新 listView 的状态参数?或者有没有更好的方法来做到这一点?

【问题讨论】:

  • 看来redux很有前途,不知道有没有react native自带的好教程。

标签: facebook callback react-native react-native-listview


【解决方案1】:

您应该在 componentDidMount 上注册一个事件侦听器并在 componentWillUnmout 上取消注册,并在您更改组件显示的数据时随时随地发出事件。

此模式的简要说明:https://colinramsay.co.uk/2015/07/04/react-native-eventemitters.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-12
    • 2015-01-03
    • 2023-03-11
    • 1970-01-01
    • 2015-09-14
    • 1970-01-01
    • 2010-11-08
    相关资源
    最近更新 更多