2

Pretty much like the official tutorial here https://facebook.github.io/react-native/docs/tutorial.html:

I have the fetchData method called in ComponentDidMount, but according to this, ComponentDidMountwould only be called once after initial rendering of the component. So should I do call the same fetchData everytime before I navigate back to this ListView, and pass the updated data as props to the ListView, and then update the listView's state parameter accordingly in componentDidUpdate? Or is there any better way to do this?

4

1 回答 1

0

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

在这里很好地了解这种模式:https ://colinramsay.co.uk/2015/07/04/react-native-eventemitters.html

于 2016-05-18T16:44:53.427 回答