1.1.1 • Published 1 year ago

local-sync-hooks v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Local Sync Hooks

Do 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!

Installation

npm i local-sync-hooks

Methods

useSyncState

Like useState but it will restore state on reload and share between tabs.

const [state, setState, ready] = useSyncState('key', { some: 'state' });

useSyncReducer

Like useReducer but it will restore state on reload and share between tabs.

const [state, dispatch, ready] = useSyncReducer('key', reducer, { some: 'state' });

createSyncHooks

Creates your own custom named sync hooks.

import createSyncHooks from 'local-sync-hooks/create';

const { useSyncState, useSyncReducer} = createSyncHooks('someProject');

or with your own localforage store

import createSyncHooks from 'local-sync-hooks/create';

const store = localforage.createInstance({ name });
const { useSyncState, useSyncReducer} = createSyncHooks('someProject', store);

License

Copyright (c) 2022, Michael Szmadzinski. (MIT License)

1.1.1

1 year ago

1.0.2

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.1.0

2 years ago