MCPcopy Create free account
hub / github.com/TanStack/query / useMutationState

Function useMutationState

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

Source from the content-addressed store, hash-verified

180 * ```
181 */
182export function useMutationState<
183 TResult = MutationState,
184 TMutation extends Mutation<any, any, any, any> =
185 MutationTypeFromResult<TResult>,
186>(
187 options: MutationStateOptions<TResult, TMutation> = {},
188 queryClient?: QueryClient,
189): Array<TResult> {
190 const mutationCache = useQueryClient(queryClient).getMutationCache()
191 const [createSnapshot] = React.useState(() =>
192 createSnapshotFactory<TResult, TMutation>(),
193 )
194 const getSnapshot = createSnapshot(mutationCache, options)
195
196 return React.useSyncExternalStore(
197 React.useCallback(
198 (onStoreChange) =>
199 mutationCache.subscribe(notifyManager.batchCalls(onStoreChange)),
200 [mutationCache],
201 ),
202 getSnapshot,
203 getSnapshot,
204 )
205}

Callers 9

useIsMutatingFunction · 0.70
PageFunction · 0.50
DatesFunction · 0.50
StatusesFunction · 0.50
VariablesFunction · 0.50
PageFunction · 0.50
MutationFunction · 0.50

Calls 4

useQueryClientFunction · 0.90
getMutationCacheMethod · 0.80
createSnapshotFactoryFunction · 0.70
subscribeMethod · 0.45

Tested by 6

PageFunction · 0.40
DatesFunction · 0.40
StatusesFunction · 0.40
VariablesFunction · 0.40
PageFunction · 0.40
MutationFunction · 0.40