2025-12-23 08:58:55 +00:00
|
|
|
import type { QueryKey } from '@tanstack/react-query'
|
2026-03-16 05:38:29 +00:00
|
|
|
import { useQueryClient } from '@tanstack/react-query'
|
|
|
|
|
import { useCallback } from 'react'
|
2024-11-19 09:16:06 +00:00
|
|
|
|
2026-03-16 05:38:29 +00:00
|
|
|
/**
|
|
|
|
|
* @deprecated Convenience wrapper scheduled for removal.
|
|
|
|
|
* Prefer binding invalidation in `useMutation` callbacks at the service layer.
|
|
|
|
|
*/
|
2025-11-12 09:59:37 +00:00
|
|
|
export const useInvalid = (key?: QueryKey) => {
|
2024-11-19 09:16:06 +00:00
|
|
|
const queryClient = useQueryClient()
|
2026-03-16 05:38:29 +00:00
|
|
|
return useCallback(() => {
|
2025-11-12 09:59:37 +00:00
|
|
|
if (!key)
|
|
|
|
|
return
|
2026-03-16 05:38:29 +00:00
|
|
|
queryClient.invalidateQueries({ queryKey: key })
|
|
|
|
|
}, [queryClient, key])
|
2024-11-19 09:16:06 +00:00
|
|
|
}
|
2025-03-07 10:10:40 +00:00
|
|
|
|
2026-03-16 05:38:29 +00:00
|
|
|
/**
|
|
|
|
|
* @deprecated Convenience wrapper scheduled for removal.
|
|
|
|
|
* Prefer binding reset in `useMutation` callbacks at the service layer.
|
|
|
|
|
*/
|
2025-11-12 09:59:37 +00:00
|
|
|
export const useReset = (key?: QueryKey) => {
|
2025-03-07 10:10:40 +00:00
|
|
|
const queryClient = useQueryClient()
|
2026-03-16 05:38:29 +00:00
|
|
|
return useCallback(() => {
|
2025-11-12 09:59:37 +00:00
|
|
|
if (!key)
|
|
|
|
|
return
|
2026-03-16 05:38:29 +00:00
|
|
|
queryClient.resetQueries({ queryKey: key })
|
|
|
|
|
}, [queryClient, key])
|
2025-03-07 10:10:40 +00:00
|
|
|
}
|