Best practices for handling normalized data and preventing duplication across multiple infinite queries #8566
-
I am working on React Native App, I have multiple infinite queries fetching posts from different feeds (network feed, user feed, etc.). Each post contains nested data about communities, participants, and other entities that get duplicated across these feeds. Current setup:
I can't invalidate all feeds because of losing scroll history Example response structure: interface FeedResponse {
posts: Array<{
id: string
content: string
community: Community // duplicated across feeds
participants: Participant[] // duplicated across feeds
}>
cursor: string
}
I'm looking for recommended patterns to:
Normalize this data structure
Share entities between queries
Update shared entities efficiently
Avoid memory duplication
Has anyone implemented something like Redux Toolkit's EntityAdapter pattern with React Query? Or what's the recommended approach for this use case?
Here is my theoretical example of how it could work, what i've got while working with AI, Will it work as expected? // Separate entities into normalized state // Separate queryKeys for each data type // Hooks for fetching shared data const useChannels = (ids: string[]) => { // Optimized feed hook return useInfiniteQuery({
}, // Post component with optimized data loading if (!post || !participant || !channel) return null; return ( // Optimized list component const postIds = useMemo(() => return (
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
sorry this was internet problems |
Beta Was this translation helpful? Give feedback.
sorry this was internet problems