swr-sync-state
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

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 ?? 0) + 1);
  };

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

Package Sidebar

Install

npm i swr-sync-state

Weekly Downloads

4

Version

1.0.4

License

MIT

Unpacked Size

5.49 kB

Total Files

6

Last publish

Collaborators

  • weaponsforge
  • vikyw