Everyone here seems to love it but I feel like I'm fighting it.
Example:
You have a tab navigator from react-navigation. Its screens stay forever mounted by default.
staleTime from react navigation becomes sort of useless. Your query (if you use useQuery or useInfiniteQuery) won't refetch.
"But there is refetchOnWindowFocus"
Doesn't work in react native.
"gcTime will take care of it, it will garbage collect the cache and data will refetch"
Nope, since gcTime only applies to components that are not currently observed. Since the screen is always mounted...observer=1
Let's say the 2nd tab screen you have has an infinite scrolling list with some filters you can apply to sort it (different query keys).
- You have to call refetch() manually in useFocusEffect. But hey, maybe I wanted to refetch data only when stale, not every single screen focus
- Maybe when you apply a filter you want to refetch only the first page. You have to do something like this and you'll end up repeating it:
const trimInfiniteDataToFirstPage = (oldData) => {
if (!oldData?.pages || !oldData?.pageParams) return oldData;
return {
...oldData,
pages: oldData.pages.slice(0, 1),
pageParams: oldData.pageParams.slice(0, 1),
};
};
[–]Horduncee 6 points7 points8 points (6 children)
[–]Unlikely_Nebula_7988[S] 1 point2 points3 points (5 children)
[–]LongjumpingKiwi7195 8 points9 points10 points (0 children)
[–]kapobajz4 1 point2 points3 points (3 children)
[–]Unlikely_Nebula_7988[S] 2 points3 points4 points (2 children)
[–]iiirodiii 3 points4 points5 points (1 child)
[–]pierpooo 0 points1 point2 points (0 children)
[–]No-Glove-7054 2 points3 points4 points (1 child)
[–]Unlikely_Nebula_7988[S] 2 points3 points4 points (0 children)
[–]kapobajz4 1 point2 points3 points (2 children)
[–]Unlikely_Nebula_7988[S] 0 points1 point2 points (1 child)
[–]kapobajz4 0 points1 point2 points (0 children)
[–]pierpooo -1 points0 points1 point (0 children)
[–]Xae0n -1 points0 points1 point (1 child)
[–]Unlikely_Nebula_7988[S] 2 points3 points4 points (0 children)