Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Add ability to reset state
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Aug 7, 2019
1 parent 368b86a commit 0a711e4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/useLoads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ export default function useLoads<R>(fn: LoadFunction<R>, config: LoadsConfig<R>
[updateFn] // eslint-disable-line react-hooks/exhaustive-deps
);

const reset = React.useCallback(() => {
dispatch({ type: STATES.IDLE });
}, []);

React.useEffect(
() => {
if (cachedRecord && loadPolicy !== LOAD_POLICIES.LOAD_ONLY) {
Expand Down Expand Up @@ -209,6 +213,7 @@ export default function useLoads<R>(fn: LoadFunction<R>, config: LoadsConfig<R>
() => ({
load: load(),
update,
reset,

response: record.response,
error: record.error,
Expand Down

0 comments on commit 0a711e4

Please sign in to comment.