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

Function useMutationState

packages/preact-query/src/useMutationState.ts:182–207  ·  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] = useState(() =>
192 createSnapshotFactory<TResult, TMutation>(),
193 )
194 const getSnapshot = createSnapshot(mutationCache, options)
195
196 return useSyncExternalStore(
197 useCallback(
198 (onStoreChange) =>
199 subscribeToSnapshot(
200 (listener) => mutationCache.subscribe(listener),
201 onStoreChange,
202 ),
203 [mutationCache],
204 ),
205 getSnapshot,
206 )
207}

Callers 9

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

Calls 6

useQueryClientFunction · 0.90
useSyncExternalStoreFunction · 0.90
subscribeToSnapshotFunction · 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