Internal function used by the useProgressiveState
hook
function useProgressiveState(cb, deps) {
const { initialState, abortManager } = useMemo(() => {
return progressiveState(cb, state => setState(state), err => setError(err));
}, deps);
const [ state, setState ] = useState(initialState);
const [ error, setError ] = useState();
useEffect(() => {
setState(initialState);
setError();
abortManager.onMount();
return () => abortManager.onUnmount();
}, [ initialState, abortManager ]);
if (error) {
throw error;
}
return state;
}
cb
-<AsyncFunction>
User-provided function that creates a set of async propssetState
-<Function>
Callback function for setting a new statesetError
-<Function>
Callback function for reporting any error encountered during executionreturn
{ initialState, abortManager }
Initial state of the hook and the abort manager that can put a stop to any further state updates
progressiveState
calls sequentialState
internally. The generator function simply
yields the generator from generateProps
, using properties returned by the callback.
See documentation of sequentialState
for more details.
See documentation of sequential
for details concerning the abort manager.