useInfiniteQuery save objects individually
I am using useInfiniteQuery to implement a flatlist with posts of my app.
Each page of useInfiniteQuery fetch 15 posts. Its is possible to save each post individually in a query like
I want to use this hook in another screen:
I want to use the data of each post individually and avoid fetching it again in another screen because i have this data inside useInfiniteQuery
Thanks
5 Replies
foreign-sapphire•3y ago
Hi 👋
I think you could leverage a staleTime and the
select option in a custom hook to achieve a similar APIfair-roseOP•3y ago
Sory buy i dont understand your solution
sensitive-blue•3y ago
If the data already exists in the
useInfiniteQuery, you could create a custom hook usePost(postId) that would call useInfiniteQuery internally and then find the post you're looking for in the returned data (data will be returned from the cache).
To avoid having to repeat useInfiniteQuery with the same key and query function, you could also wrap that in a custom hook usePosts(). Then usePost() would call usePosts() and look for the post id in the results.foreign-sapphire•3y ago
As above. Thanks for elaborating Julien 🙂
fair-roseOP•3y ago
Thanks you so much both of you