(
options: Accessor<MutationStateOptions<TResult>> = () => ({}),
queryClient?: Accessor<QueryClient>,
)
| 28 | } |
| 29 | |
| 30 | export function useMutationState<TResult = MutationState>( |
| 31 | options: Accessor<MutationStateOptions<TResult>> = () => ({}), |
| 32 | queryClient?: Accessor<QueryClient>, |
| 33 | ): Accessor<Array<TResult>> { |
| 34 | const client = createMemo(() => useQueryClient(queryClient?.())) |
| 35 | const mutationCache = createMemo(() => client().getMutationCache()) |
| 36 | |
| 37 | const [result, setResult] = createSignal( |
| 38 | getResult(mutationCache(), options()), |
| 39 | ) |
| 40 | |
| 41 | createEffect(() => { |
| 42 | const unsubscribe = mutationCache().subscribe(() => { |
| 43 | const nextResult = replaceEqualDeep( |
| 44 | result(), |
| 45 | getResult(mutationCache(), options()), |
| 46 | ) |
| 47 | if (result() !== nextResult) { |
| 48 | setResult(nextResult) |
| 49 | } |
| 50 | }) |
| 51 | |
| 52 | onCleanup(unsubscribe) |
| 53 | }) |
| 54 | |
| 55 | return result |
| 56 | } |
searching dependent graphs…