local-sync-hooks
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

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)

Readme

Keywords

none

Package Sidebar

Install

npm i local-sync-hooks

Weekly Downloads

6

Version

1.1.1

License

MIT

Unpacked Size

9.24 kB

Total Files

7

Last publish

Collaborators

  • smujmaiku