-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CU-86duf5a5c - NEON3 - Refresh Button on Tokens, Transaction and Over…
…view Screens
- Loading branch information
1 parent
eddbfab
commit b4803c6
Showing
6 changed files
with
73 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useCallback, useSyncExternalStore } from 'react' | ||
import { notifyManager, QueryFilters, useIsFetching, useQueryClient } from '@tanstack/react-query' | ||
|
||
export function useRefetch(filters?: QueryFilters) { | ||
const queryClient = useQueryClient() | ||
|
||
const isRefetching = useIsFetching({ ...filters, predicate: query => query.state.status !== 'pending' }) | ||
|
||
const refetch = useCallback(async () => { | ||
await queryClient.invalidateQueries({ ...filters, refetchType: 'all' }) | ||
}, [queryClient, filters]) | ||
|
||
return { | ||
refetch, | ||
isRefetching, | ||
} | ||
} | ||
|
||
export function useLastUpdated(filters?: QueryFilters) { | ||
const queryClient = useQueryClient() | ||
|
||
const queryCache = queryClient.getQueryCache() | ||
|
||
return useSyncExternalStore( | ||
useCallback(onStoreChange => queryCache.subscribe(notifyManager.batchCalls(onStoreChange)), [queryCache]), | ||
() => { | ||
const queries = queryCache.findAll(filters) | ||
const sortedQueries = queries.sort((a, b) => b.state.dataUpdatedAt - a.state.dataUpdatedAt) | ||
return sortedQueries[0].state.dataUpdatedAt | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters