Skip to content

Latest commit

 

History

History
42 lines (33 loc) · 1.44 KB

progressiveState.md

File metadata and controls

42 lines (33 loc) · 1.44 KB

progressiveState(cb)

Internal function used by the useProgressiveState hook

Syntax

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;
}

Parameters

  • cb - <AsyncFunction> User-provided function that creates a set of async props
  • setState - <Function> Callback function for setting a new state
  • setError - <Function> Callback function for reporting any error encountered during execution
  • return { initialState, abortManager } Initial state of the hook and the abort manager that can put a stop to any further state updates

notes

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.