-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e940260
commit 1ff8771
Showing
7 changed files
with
59 additions
and
11 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useQueryClient } from "@tanstack/react-query"; | ||
import { useCallback } from "react"; | ||
|
||
/** | ||
* | ||
* @required This hook needs to be used within the QueryClientProvider | ||
* @param queryKeys An Array of Query : [ [ "key1" ], [ "key2" ] ] | ||
* @param waitFor Optional - Time to wait before refetching | ||
* @returns refetchQuery - A function that takes in the query keys array to refetch | ||
* @example refetchQuery([["refetchOnBlock","myQuery"],["myOtherQuery"]]) | ||
* @warning The order of keys in the query key array matters | ||
*/ | ||
export const useQueryRefetch = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
const refetchQuery = useCallback( | ||
async (queryKeys: string[][], waitFor = 4000) => { | ||
await new Promise((res) => setTimeout(() => res(true), waitFor)); | ||
|
||
for (const queryKey of queryKeys) { | ||
queryClient.refetchQueries(queryKey); | ||
} | ||
}, | ||
[queryClient] | ||
); | ||
|
||
return refetchQuery; | ||
}; |
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
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
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
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
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
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