React-native FlatList not rerendering row when props change

后端 未结 7 606
闹比i
闹比i 2021-02-01 14:33

I\'m having an issue with the new FlatList component. Specifically, it does not rerender it\'s rows, even though props that the row is dependent on changes.


The F

7条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-01 15:31

    In my case I just made a simple mistake when using keyExtractor

    I changed

    keyExtractor={(item, index) => index.toString()} 
    

    To

    keyExtractor={(item, index) => item.key} 
    

    I was seeing some strange effect after filtering my list where props of filtered out components were being rendered in place of new component's props, my hunch is that because I was using the index of the array rather than a unique key, I was just passing the old props to the new component even though the base component was in fact changing.

提交回复
热议问题