Local Sync hooks
npm install local-sync-hooksDo you need some simple storage for your React states and reducers?
Does your React app live in two or more tabs at once?
Do you like BroadcastChannel and IndexedDB?
Local sync hooks can replicate your state across your many browser tabs!
npm i local-sync-hooks
Like useState but it will restore state on reload and share between tabs.
``js`
const [state, setState, ready] = useSyncState('key', { some: 'state' });
Like useReducer but it will restore state on reload and share between tabs.
`js`
const [state, dispatch, ready] = useSyncReducer('key', reducer, { some: 'state' });
Creates your own custom named sync hooks.
`js
import createSyncHooks from 'local-sync-hooks/create';
const { useSyncState, useSyncReducer} = createSyncHooks('someProject');
`
or with your own localforage store
`js
import createSyncHooks from 'local-sync-hooks/create';
const store = localforage.createInstance({ name });
const { useSyncState, useSyncReducer} = createSyncHooks('someProject', store);
``
Copyright (c) 2022, Michael Szmadzinski. (MIT License)