logos-ordinals-dashboard/apis/operators/useGetOperators.ts

33 lines
720 B
TypeScript
Raw Normal View History

2024-09-26 15:40:01 +00:00
import { useQuery, useQueryClient } from '@tanstack/react-query'
2024-09-27 14:46:45 +00:00
import operators from '../../data/operators.json'
2024-09-26 15:40:01 +00:00
const useQueryOptions = {
refetchOnWindowFocus: false,
staleTime: 60 * 1000,
retry: 1,
}
export const fetchData = async () => {
2024-09-27 14:46:45 +00:00
return operators
// return await api.get('/operators').then((res) => res.data)
2024-09-26 15:40:01 +00:00
}
const useGetOperators = () => {
const queryKey = ['getOperators']
const queryClient = useQueryClient()
const updateCache = (newData: any) => {
queryClient.setQueryData(queryKey, newData)
}
const response = useQuery({
queryKey: queryKey,
queryFn: fetchData,
...useQueryOptions,
})
return { ...response, updateCache }
}
export default useGetOperators