Skip to content

Instantly share code, notes, and snippets.

@willprice76
Created May 1, 2020 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willprice76/f1fceeb12154baee4c88f23cfae98d83 to your computer and use it in GitHub Desktop.
Save willprice76/f1fceeb12154baee4c88f23cfae98d83 to your computer and use it in GitHub Desktop.
Using multiple reducers for different lifecycles
//component state
const [{ data:initialData, isBusy:isLoading, hasError:loadingFailed, errorMessage:loadingError }, dispatch] = useReducer(
createActionReducer<Recipe[]>(),
{ isBusy: true, hasError: false }
);
const [{ data:updatedData, isBusy:isUpdating, hasError:updateFailed, errorMessage:updateError }, dispatch] = useReducer(
createActionReducer<Recipe[]>(),
{ isBusy: false, hasError: false }
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment