dai-shi / react-hooks-global-state

[NOT MAINTAINED] Simple global state for React with Hooks API without Context API
https://www.npmjs.com/package/react-hooks-global-state
MIT License
1.1k stars 62 forks source link

Is it possible to change a value outside a component? #57

Closed SrBrahma closed 3 years ago

SrBrahma commented 3 years ago

In MobX, for example, I can change at any place a value that will cause the related components to re-render.

MobX would solve my issue, but, it's a bit of overkill, as your package is much lighter.

Is it possible to change a global state outside a component?

dai-shi commented 3 years ago

sure, that's the whole point of this library.

setGlobalState: a function to set a global state by key outside React

const { useGlobalState, setGlobalState } = createGlobalState({ count: 0 });

setGlobalState('count', 1);
SrBrahma commented 3 years ago

Damn, haha! I was expecting* to get some workaround, not a built in way.

Thanks for the quick answer, and also, for the package!