React Native - FlatList - Internal State

孤街浪徒 提交于 2019-12-22 10:30:00

问题


I'm using a FlatList in order to implement a Store View in my react-native app.

I'm retrieving the store items from an API Call that is done in the componentDidMount cycle step of my component and then store it in my local state.

I've found in the Flatlist documentation this sentence :

Internal state is not preserved when content scrolls out of the render window. Make sure all your data is captured in the item data or external stores like Flux, Redux, or Relay.

I was wondering what it meant. I'm just using my local state and it seems to work just fine. Is there any issue by doing so ? Could you provide me more informations about this particular point ?

Also, if you have any advice or optimization about my use-case, feel free to add them.

Thanks for your time.


回答1:


Let's say you have a Contacts component with a FlatList rendering Contact component for each item in your data. Let's also say that these contacts are selectable. If you store these select value ( for example selected: true) in Contact components internal state and not in Contacts components state, when the item scrolls out its going to be unmounted and the state of that item going to be reset. If you hold it in the global data it will be created with the last state.

Hope I was able to explain.



来源:https://stackoverflow.com/questions/48926314/react-native-flatlist-internal-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!