Created
September 15, 2023 06:41
-
-
Save osamajavaid/c52c5f8d46d1ef0122c5f2611b1b0516 to your computer and use it in GitHub Desktop.
React Query: Invalidate multiple queries
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 { useQuery, useQueryClient } from 'react-query'; | |
// Inside your component or function... | |
const queryClient = useQueryClient(); | |
// Example: Invalidate a single query | |
queryClient.invalidateQueries('yourQueryKey'); | |
// Example: Invalidate multiple queries | |
queryClient.invalidateQueries(['queryKey1', 'queryKey2', 'queryKey3']); | |
// You can also pass additional options as the second argument | |
queryClient.invalidateQueries('yourQueryKey', { | |
refetchActive: true, // Refetch currently active queries | |
refetchInactive: true, // Refetch inactive queries as well | |
throwOnError: true, // Throw an error if the query fails to refetch | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment