I have an array of posts in a redux reducer that I update via the onEndReached prop of my FlatList. The issue is, every time the state changes, the entire list is re-rendered rather than the affected post item.
// Posts Feed Screen
const posts = useSelector(state => state.posts)
const renderItem = useCallback(
({ item }) => (
<Post post={item} />
),
[]
)
const keyExtractor = useCallback(
(item, index) => `${item.id}${index}`,
[]
)
return (
<FlatList
ref={ref}
data={posts}
keyExtractor={keyExtractor}
renderItem={renderItem}
onEndReached={onEndReached}
onEndReachedThreshold={0.6}
showsVerticalScrollIndicator={false}
removeClippedSubviews
/>
)
// Post Component
const Post = ({ post }) => {
return (
<View style={styles.post}>
<PostHeader />
<View style={styles.postBody}>
<PostContent />
<PostFooter />
</View>
</View>
)
}
const isEqual = (prevProps, nextProps) => {
return prevProps.post.id === nextProps.post.id
}
export default React.memo(Post, isEqual)
As you can see, I'm utilizing useCallback on renderItem function, also using React.memo on the export of my Post Component - however, the FlatList still renders every post item on state change.
What am I missing here?