사이즈가 큰 앱에서 리액트 쿼리를 이용하는 경우

queryClient.ts

import { QueryClient } from "@tanstack/react-query";

const queryClient = new QueryClient({
	defaultOptions: {
	    queries: {
	      retry: 3,
	      useErrorBoundary: true,
	    },
	    mutations: {
	      useErrorBoundary: true,
	    },
	  },
});

Custom Hook

예시

async function getTreatments(): Promise<Treatment[]> {
  const { data } = await axiosInstance.get('/treatments');
  return data;
}

export function useTreatments(): Treatment[] {
  const { data } = useQuery({
    queryKey: [queryKeys.treatments],
    queryFn: getTreatments,
  });

  return data;
}