问题
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