It not fresh data when time out: staletime
Hello everyone
I using react query and react native
// QUERY: query check ins list
useInfiniteQuery({
queryKey: ['getCheckinListFn', [searchParams]],
queryFn: (context) => {
const { pageParam } = context {}
return getCheckinListFn({
...searchParams,
page: pageParam pageDefault,
from_time: toUnix(searchParams.from_time),
to_time: toUnix(searchParams.to_time),
})
},
initialPageParam: 1,
getNextPageParam: (lastPage, __, lastPageParam: number) => {
const length = lastPage.data.length
// console.info(lastPage)
if (length < pageSize) {
return undefined
}
return lastPageParam + 1
},
...options,
staleTime: 5 * 1000, // 5 seconds
placeholderData: keepPreviousData,
})
I using this in screen list, after that I go to detail item screen
and go back to screen list but it not auto fresh data, I mean when after 5 seconds it not fresh data when I go back screen list, please help me, thank you so much
3 Replies
metropolitan-bronze•15mo ago
React Native | TanStack Query React Docs
React Query is designed to work out of the box with React Native, with the exception of the devtools, which are only supported with React DOM at this time.
There is a 3rd party Expo plugin which you can try: https://github.com/expo/dev-plugins/tree/main/packages/react-query
like-goldOP•15mo ago
yes i tried this and it worked when i used refetch() function
But I want to optimize it more than using the staletime I have configured for 5 seconds
As far as I know, when used with the web, it will automatically fresh data after 5 seconds, if the component is mounted next time.
Do you have a way similar to the web?


like-goldOP•15mo ago
the data will be considered fresh for that same amount of time
I mean like this