Skip to content

enigma49/react-tab-sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-tab-sync

Sync React state across browser tabs instantly.

Demo

demo

Install

npm install react-tab-sync

Usage

import { useTabSync } from "react-tab-sync";

function App() {
  const [isLoggedIn, setIsLoggedIn] = useTabSync("auth", true);

  return (
    <div>
      <h1>{isLoggedIn ? "Logged In" : "Logged Out"}</h1>

      <button onClick={() => setIsLoggedIn(false)}>Logout</button>
    </div>
  );
}

Why?

When users open multiple tabs, state often gets out of sync (auth, theme, etc).

This hook keeps them in sync automatically using the browser storage event.

License

ISC

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors