Skip to content

Instantly share code, notes, and snippets.

View dineshigdd's full-sized avatar

Daminda Dinesh W Imaduwa Gamage dineshigdd

View GitHub Profile
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'] })
const query = useQuery({
queryKey: ['users'],
queryFn: getUsers,
staleTime: 5000,
cacheTime: 60000
})
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() )
const { isLoading, isError, data, error } = useQuery( { queryKey: ['todos'], queryFn: getTodos });

Introduction to Higher-Order Functions

Lessons

Slides 1

Slides 2

Two Forms of Functions