1.0.4 • Published 12 months ago

swr-sync-state v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

swr-sync-state

a small library to wrap SWR, enabling SWR to function as global state manager

to start

npm i swr-sync-state

usage

// inside react component
export const SomeComponent = () => {
  const key = 'someKey';
  const state = useSyncSWR(key) ?? 0;

  const incrementHandler = () => {
    setSyncSWR(key, (p) => p + 1);
  };

  return (
    <div>
      <div>Counter : {state}</div>
      <button onClick={incrementHandler}>Increment</button>
    </div>
  );
};
1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago