| 180 | * ``` |
| 181 | */ |
| 182 | export 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 | } |