我正在使用 React-native 和 React-query,我想在卸载屏幕时停止自动重新获取。
目前,当我转到目标屏幕时,我使用间隔参数调用查询:
const { data: mission } = useMissionFetcher(missionSelectedId, 5000)
使用MissionFetcher:
export const useMissionFetcher = (idMission: string, interval: number): QueryResult<MissionMobile> => {
const missionsQueryFn = () => getMission(idMission)
return useQuery([QueryKeys.mission, idMission], missionsQueryFn, {
...baseReactQueryConfig,
refetchInterval: interval,
})
}
基本反应查询配置:
export const baseReactQueryConfig = {
refetchOnWindowFocus: false,
staleTime: Infinity,
退出屏幕时如何停止重新获取?