MCPcopy
hub / github.com/TanStack/query / useMutationState

Function useMutationState

packages/react-query/src/useMutationState.ts:42–75  ·  view source on GitHub ↗
(
  options: MutationStateOptions<TResult> = {},
  queryClient?: QueryClient,
)

Source from the content-addressed store, hash-verified

40}
41
42export function useMutationState<TResult = MutationState>(
43 options: MutationStateOptions<TResult> = {},
44 queryClient?: QueryClient,
45): Array<TResult> {
46 const mutationCache = useQueryClient(queryClient).getMutationCache()
47 const optionsRef = React.useRef(options)
48 const result = React.useRef<Array<TResult>>(null)
49 if (!result.current) {
50 result.current = getResult(mutationCache, options)
51 }
52
53 React.useEffect(() => {
54 optionsRef.current = options
55 })
56
57 return React.useSyncExternalStore(
58 React.useCallback(
59 (onStoreChange) =>
60 mutationCache.subscribe(() => {
61 const nextResult = replaceEqualDeep(
62 result.current,
63 getResult(mutationCache, optionsRef.current),
64 )
65 if (result.current !== nextResult) {
66 result.current = nextResult
67 notifyManager.schedule(onStoreChange)
68 }
69 }),
70 [mutationCache],
71 ),
72 () => result.current,
73 () => result.current,
74 )!
75}

Callers 5

useIsMutatingFunction · 0.70
VariablesFunction · 0.50
MutationFunction · 0.50

Calls 5

useQueryClientFunction · 0.90
replaceEqualDeepFunction · 0.90
getMutationCacheMethod · 0.80
getResultFunction · 0.70
subscribeMethod · 0.45

Tested by 2

VariablesFunction · 0.40
MutationFunction · 0.40

Used in the wild real call sites across dependent graphs

searching dependent graphs…