mirror of
https://github.com/acid-info/logos-ordinals-dashboard.git
synced 2025-02-05 01:53:49 +00:00
32 lines
679 B
TypeScript
32 lines
679 B
TypeScript
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
|
import { api } from '../../common/api'
|
|
|
|
const useQueryOptions = {
|
|
refetchOnWindowFocus: false,
|
|
staleTime: 60 * 1000,
|
|
retry: 1,
|
|
}
|
|
|
|
export const fetchData = async () => {
|
|
return await api.get('/pillars').then((res) => res.data)
|
|
}
|
|
|
|
const useGetPillars = () => {
|
|
const queryKey = ['getPillars']
|
|
const queryClient = useQueryClient()
|
|
|
|
const updateCache = (newData: any) => {
|
|
queryClient.setQueryData(queryKey, newData)
|
|
}
|
|
|
|
const response = useQuery({
|
|
queryKey: queryKey,
|
|
queryFn: fetchData,
|
|
...useQueryOptions,
|
|
})
|
|
|
|
return { ...response, updateCache }
|
|
}
|
|
|
|
export default useGetPillars
|