(props: {
onFetch: () => Promise<any>;
persistedState?: typeof persistedFetchState;
})
| 91 | const persistedFetchState = actorRef.getPersistedSnapshot(); |
| 92 | |
| 93 | const Fetcher = (props: { |
| 94 | onFetch: () => Promise<any>; |
| 95 | persistedState?: typeof persistedFetchState; |
| 96 | }) => { |
| 97 | const mergedProps = mergeProps( |
| 98 | { |
| 99 | onFetch: () => new Promise((res) => res('some data')) |
| 100 | }, |
| 101 | props |
| 102 | ); |
| 103 | const [snapshot, send] = useActor( |
| 104 | fetchMachine.provide({ |
| 105 | actors: { |
| 106 | fetchData: fromPromise(mergedProps.onFetch) |
| 107 | } |
| 108 | }), |
| 109 | { |
| 110 | snapshot: mergedProps.persistedState |
| 111 | } |
| 112 | ); |
| 113 | |
| 114 | return ( |
| 115 | <Switch fallback={null}> |
| 116 | <Match when={snapshot.matches('idle')}> |
| 117 | <button onclick={(_) => send({ type: 'FETCH' })}>Fetch</button>; |
| 118 | </Match> |
| 119 | <Match when={snapshot.matches('loading')}> |
| 120 | <div>Loading...</div> |
| 121 | </Match> |
| 122 | <Match when={snapshot.matches('success')}> |
| 123 | Success! Data: <div data-testid="data">{snapshot.context.data}</div> |
| 124 | </Match> |
| 125 | </Switch> |
| 126 | ); |
| 127 | }; |
| 128 | |
| 129 | it('should work (default initial snapshot)', async () => { |
| 130 | render(() => ( |
nothing calls this directly
no test coverage detected
searching dependent graphs…