Middleware Hooks

usePersist

usePersist

usePersist lets you save the state of your reducer. Inspired from redux-persist.

Note: This is experimental. It relies on the function name of reducer in order to cache the value.

Usage

import { usePersist, resetStorage } from 'middleware-hooks';
const App = () => {
const [store, dispatch] = usePersist(reducer, initialState);
return (
<>
<h1>Hello World!</h1>
<button onClick={() => dispatch(resetStorage())}>Reset Storage</button>
</>
);
};

Example

Edit this page on GitHub

On this page