From 0a711e4c980308d4c2ee3890f1fe411aab52998c Mon Sep 17 00:00:00 2001 From: jxom Date: Wed, 7 Aug 2019 13:09:33 +1000 Subject: [PATCH] Add ability to reset state --- src/useLoads.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/useLoads.ts b/src/useLoads.ts index 1b2cbe4..10a8dcc 100644 --- a/src/useLoads.ts +++ b/src/useLoads.ts @@ -180,6 +180,10 @@ export default function useLoads(fn: LoadFunction, config: LoadsConfig [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) { @@ -209,6 +213,7 @@ export default function useLoads(fn: LoadFunction, config: LoadsConfig () => ({ load: load(), update, + reset, response: record.response, error: record.error,