Created
December 22, 2020 02:14
-
-
Save mgtitimoli/231e1efae8f857db6fd8c80648acb98d to your computer and use it in GitHub Desktop.
useNonCachedQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {useEffect} from "react"; | |
import {useQuery, useQueryClient} from "react-query"; | |
import type { | |
QueryKey, | |
QueryFunction, | |
UseQueryOptions, | |
UseQueryResult | |
} from "react-query"; | |
const useNonCachedQuery = < | |
TData = unknown, | |
TError = unknown, | |
TQueryFnData = TData | |
>( | |
queryKey: QueryKey, | |
queryFn: QueryFunction<TQueryFnData | TData>, | |
options?: UseQueryOptions<TData, TError, TQueryFnData> | |
): UseQueryResult<TData, TError> => { | |
const queryClient = useQueryClient(); | |
// eslint-disable-next-line react-hooks/exhaustive-deps | |
useEffect(() => () => queryClient.removeQueries(queryKey), []); | |
return useQuery(queryKey, queryFn, options); | |
}; | |
export default useNonCachedQuery; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment