This file contains hidden or 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 { useQueryClient } from '@tanstack/react-query' | |
| //creating queryClient object using useQueryClient hook | |
| const queryClient = useQueryClient() | |
| // Invalidate every query in the cache | |
| queryClient.invalidateQueries() | |
| // Invalidate every query with a key that starts with 'users' | |
| queryClient.invalidateQueries({ queryKey: ['users'] }) |
This file contains hidden or 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
| const query = useQuery({ | |
| queryKey: ['users'], | |
| queryFn: getUsers, | |
| staleTime: 5000, | |
| cacheTime: 60000 | |
| }) |
This file contains hidden or 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
| const AddUser = useMutation({ | |
| mutationFn: ( user ) => { | |
| return fetch('https://jsonplaceholder.typicode.com/users', | |
| { | |
| method:'post', | |
| headers: { | |
| "Content-Type": "application/json", | |
| }, | |
| body:JSON.stringify( user ) | |
| }).then( res => res.json() ) |
This file contains hidden or 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
| const { isLoading, isError, data, error } = useQuery( { queryKey: ['todos'], queryFn: getTodos }); |