Add feature order cycle guide

This commit is contained in:
Misode
2022-05-09 22:45:45 +02:00
parent 1486a3f977
commit 86cdde9d70
6 changed files with 111 additions and 3 deletions

View File

@@ -7,12 +7,15 @@ export function useAsync<R>(
fn: () => Promise<R | typeof AsyncCancel>,
inputs: Inputs = [],
initialState: AsyncState<R> = { loading: true },
): AsyncState<R> {
): AsyncState<R> & { refresh: () => Promise<unknown> } {
const [state, callback] = useAsyncFn<R, () => Promise<R | typeof AsyncCancel>>(fn, inputs, initialState)
useEffect(() => {
callback()
}, [callback])
return state
return {
...state,
refresh: callback,
}
}