
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-state-sync
Advanced tools
Create synchronized state instances, then use them throughout your app. Opt into localStorage or sessionStorage persistence to sync the state across multiple tabs.
import { createSyncState } from 'react-state-sync';
// create a synchronized state instance
const counter = createSyncState({ defaultValue: 0 });
// extract the getter custom hook and an updater function
const { useSyncValue, setSyncValue } = counter;
function CounterDisplay() {
// get the count value
const count = useSyncValue();
return <div>Count is: {count}</div>;
}
function DoubleDisplay() {
// get the count value and transform it
const doubleCount = useSyncValue(n => n * 2);
return <div>Double is: {doubleCount}</div>;
}
function Counter() {
return <button onClick={() => setSyncValue(n => n + 1)}>increment</button>;
}
function Reset() {
return <button onClick={() => setSyncValue(0)}>reset</button>;
}
function App() {
return (
<>
<CounterDisplay />
<DoubleDisplay />
<Counter />
<Reset />
</>
);
}
localStoragePersisting the state to a storage layer will sync your state across multiple opened tabs.
First, initialize the state instance with the storage option set to window.localStorage and give it a unique key name:
// in ./sharedState
export const counter = createSyncState({
defaultValue: 0,
storage: window.localStorage,
key: 'counter',
});
Then just use the state as normal in one tab and watch your app get updated in the other tabs:
import { counter } from './sharedState';
const { useSyncValue, setSyncValue } = counter;
// part of the app rendering in a browser tab
function Counter() {
const count = useSyncValue();
return <button onClick={() => setSyncValue(n => n + 1)}>increment {count}</button>;
}
import { counter } from './sharedState';
const { useSyncValue } = counter;
// part of the app rendering in a different tab
function CounterDisplay() {
const count = useSyncValue();
return <div>Count is: {count}</div>;
}
FAQs
A custom React hook for synchronized state
We found that react-state-sync demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.