17.7KB
(react-query is 2.18MB
)string | undefined
์ dataํ์
์ ๊ฐ์ง๊ณ initialData๋ฅผ null
๋ก ์ค์ ํ๋ฉด data ํ์
์ด string | null | undefined
๊ฐ ๋ฉ๋๋ค.yarn add simple-react-query
QueryClient has queryCache.
import { QueryClient, QueryClientProvider } from "simple-react-query";
<QueryClientProvider value={QueryClient}>
<App />
</QueryClientProvider>;
const {
refetch,
isLoading,
isError,
data,
error,
setData,
isSuccess,
clearRefetchInterval,
isFetched
} = useQuery<TypeOfResponseData>({
enabled: true,
query: () => fetch(...),
initialData: {},
onSuccess: () => console.log("fetch success!"),
refetchInterval: 5000,
isEqualToPrevDataFunc: (a,b) => a.id === b.id,
cacheTime: 5000,
queryKeys: ["User", "id"]
});
enabled
: auto fetch, when useQuery calledquery
: fetch functiononSuccess (optional)
: action after query fetched successfullyinitialData (optional)
: set initial datarefetchInterval (optional)
: refetch interval (ms)(background ok)isEqualToPrevDataFunc (optional)
: when newData fetched, isEqualToPrevDataFunc called with (newData, prevData), if false update newData, true don't update newData because it is same.cacheTime (optional)
: caching time useQuery's return data. (ms) default is 0.queryKeys (optional)
: caching is decided by queryKeys. It must be array.refetch
: refetch queryisLoading
: fetch is not completeisError
: fetch has errordata
: fetch's return data (or cached data)error
: error objectsetData
: update data stateisSuccess
: fetch is complete successfullyclearRefetchInterval
: clear interval refetchisFetched
: query is fetched more then 1 timeconst { isLoading, isError, error, data, mutation } = useMutation<
TypeRequestData,
TypeResponseData
>({
query: (_data: TypeRequestData) => fetch(_data),
onSuccess: () => {
console.log("mutation successfully");
}
});
query
: mutation fetch functiononSuccess (optional)
: action after query fetched successfullyisLoading
: fetch is not completeisError
: fetch has errordata
: fetch's return dataerror
: error objectmutation
: wrapped async fetch function, use this function instead fetch