ra-core
Version:
Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React
23 lines (21 loc) • 592 B
text/typescript
import { useCallback } from 'react';
import { useQueryClient } from '@tanstack/react-query';
/**
* Hook for triggering a page refresh. Returns a callback function.
*
* The callback invalidates all queries and refetches the active ones.
* Any component depending on react-query data will be re-rendered.
*
* @example
*
* const refresh = useRefresh();
* const handleClick = () => {
* refresh();
* };
*/
export const useRefresh = () => {
const queryClient = useQueryClient();
return useCallback(() => {
queryClient.invalidateQueries();
}, [queryClient]);
};