I am using React-native and React-query and I want stop the automatic refetch when the screen is unmounted.
Currently, when I go to my target screen, I call a query with an interval parameter :
const { data: mission } = useMissionFetcher(missionSelectedId, 5000)
useMissionFetcher :
export const useMissionFetcher = (idMission: string, interval: number): QueryResult<MissionMobile> => {
const missionsQueryFn = () => getMission(idMission)
return useQuery([QueryKeys.mission, idMission], missionsQueryFn, {
...baseReactQueryConfig,
refetchInterval: interval,
})
}
baseReactQueryConfig :
export const baseReactQueryConfig = {
refetchOnWindowFocus: false,
staleTime: Infinity,
How can I do to stop this refetch when I quit the screen ?