@alevnyacow/shared-react-variables
TypeScript icon, indicating that this package has built-in type declarations

2.0.5 • Public • Published

Shared React variables

npm GitHub GitHub last commit npm GitHub top language code style: prettier

About

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?

🔍 Example

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>
};

💡 Codesandbox

https://codesandbox.io/s/react-shared-variables-example-f7feo7

Package Sidebar

Install

npm i @alevnyacow/shared-react-variables

Weekly Downloads

2

Version

2.0.5

License

MIT

Unpacked Size

15.5 kB

Total Files

15

Last publish

Collaborators

  • alevnyacow