8000 GitHub - ahmedvila/use-share-state: React hook for share state between tabs/windows
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ahmedvila/use-share-state

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

React Shared State Hook 🔗

React hook for state synchronization between (windows, tabs).

This hook is based on a broadcast-channel library that works in New Browsers, Old Browsers, WebWorkers and NodeJs.

Installation

$ npm install use-share-state

Usage

import useShareState from "use-share-state";

const App = () => {
  const [state, setState] = useShareState(0);

  const increment = useCallback(() => {
    setState(state + 1);
  }, [state]);

  const decrement = useCallback(() => {
    setState(state - 1);
  }, [state]);

  return (
    <div className="App">
      Counter: {state}
      <button onClick={increment}>+</button>
      <button onClick={decrement}>-</button>
    </div>
  );
}

License

MIT © Muslim Guseinov

About

React hook for share state between tabs/windows

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 36.7%
  • JavaScript 27.1%
  • HTML 20.9%
  • CSS 15.3%
0