mirror of
https://github.com/acid-info/logos-ordinals-dashboard.git
synced 2025-02-09 20:04:52 +00:00
32 lines
719 B
TypeScript
32 lines
719 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('/block/current-btc-block').then((res) => res.data)
|
|
}
|
|
|
|
const useGetCurrentBTCBlock = () => {
|
|
const queryKey = ['getCurrentBTCBlock']
|
|
const queryClient = useQueryClient()
|
|
|
|
const updateCache = (newData: any) => {
|
|
queryClient.setQueryData(queryKey, newData)
|
|
}
|
|
|
|
const response = useQuery({
|
|
queryKey: queryKey,
|
|
queryFn: fetchData,
|
|
...useQueryOptions,
|
|
})
|
|
|
|
return { ...response, updateCache }
|
|
}
|
|
|
|
export default useGetCurrentBTCBlock
|