Shared React variables provide you easy and comfortable global state management based on hooks. You can treat it like a global mutable useState. Isn't it awesome?
import { createUseSharedVariable } from "@alevnyacow/shared-react-variables";
const [useTimer] = createUseSharedVariable({ ticks: 0 });
const Timer = () => {
const timer = useTimer();
useEffect(() => {
setInterval(() => {
timer.ticks++;
}, 1000);
}, []);
return <div>{timer.ticks}</div>
};
const AnotherTimerWithSameState = () => {
// using pretty same timer in another place
const timer = useTimer();
return <div>{timer.ticks}</div>
};
https://codesandbox.io/s/react-shared-variables-example-f7feo7