mirror of
https://github.com/acid-info/logos-ordinals-dashboard.git
synced 2025-02-05 18:13:47 +00:00
37 lines
746 B
TypeScript
37 lines
746 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('/epochs').then((res) => res.data)
|
|
}
|
|
|
|
interface Props {
|
|
enabled: boolean
|
|
}
|
|
|
|
const useGetEpochs = ({ enabled }: Props) => {
|
|
const queryKey = ['getEpochs']
|
|
const queryClient = useQueryClient()
|
|
|
|
const updateCache = (newData: any) => {
|
|
queryClient.setQueryData(queryKey, newData)
|
|
}
|
|
|
|
const response = useQuery({
|
|
queryKey: queryKey,
|
|
queryFn: fetchData,
|
|
enabled,
|
|
...useQueryOptions,
|
|
})
|
|
|
|
return { ...response, updateCache }
|
|
}
|
|
|
|
export default useGetEpochs
|