({
onFetch = () => {
return new Promise((res) => res('some data'));
},
persistedState
})
| 88 | onFetch: () => Promise<any>; |
| 89 | persistedState?: Snapshot<unknown>; |
| 90 | }> = ({ |
| 91 | onFetch = () => { |
| 92 | return new Promise((res) => res('some data')); |
| 93 | }, |
| 94 | persistedState |
| 95 | }) => { |
| 96 | const [current, send] = useActor( |
| 97 | fetchMachine.provide({ |
| 98 | actors: { |
| 99 | fetchData: fromPromise(onFetch) |
| 100 | } |
| 101 | }), |
| 102 | { |
| 103 | snapshot: persistedState |
| 104 | } |
| 105 | ); |
| 106 | |
| 107 | switch (current.value) { |
| 108 | case 'idle': |
| 109 | return <button onClick={(_) => send({ type: 'FETCH' })}>Fetch</button>; |
| 110 | case 'loading': |
| 111 | return <div>Loading...</div>; |
| 112 | case 'success': |
| 113 | return ( |
| 114 | <div> |
| 115 | Success! Data: <div data-testid="data">{current.context.data}</div> |
| 116 | </div> |
| 117 | ); |
| 118 | default: |
| 119 | return null; |
| 120 | } |
| 121 | }; |
| 122 | |
| 123 | it('should work with the useActor hook', async () => { |
| 124 | render(<Fetcher onFetch={() => new Promise((res) => res('fake data'))} />); |
nothing calls this directly
no test coverage detected
searching dependent graphs…