19 lines
1.1 KiB
TypeScript
19 lines
1.1 KiB
TypeScript
import { myLevelQueryKey } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
|
import { focusManager, keepPreviousData, MutationCache, QueryClient } from '@tanstack/react-query';
|
|
import { AppState, Platform } from 'react-native';
|
|
|
|
// 앱이 다시 앞으로 오면 '포커스'로 보고, 5분 넘게 묵은 데이터만 다시 받는다
|
|
if (Platform.OS !== 'web') {
|
|
focusManager.setEventListener((setFocused) => {
|
|
const sub = AppState.addEventListener('change', (state) => setFocused(state === 'active'));
|
|
return () => sub.remove();
|
|
});
|
|
}
|
|
|
|
// 웹과 같은 기본값: 다시 받는 동안 이전 결과를 그대로 두어 화면이 비지 않게 한다
|
|
export const queryClient: QueryClient = new QueryClient({
|
|
defaultOptions: { queries: { staleTime: 5 * 60 * 1000, retry: 1, placeholderData: keepPreviousData } },
|
|
// 각을 주는 일(좋아요·댓글·글·공유·사주)은 모두 mutation 이라, 끝나면 내 레벨을 다시 받는다 (웹 main.tsx)
|
|
mutationCache: new MutationCache({ onSuccess: () => queryClient.invalidateQueries({ queryKey: myLevelQueryKey() }) }),
|
|
});
|