4 ms·
You might like the atomic state management libraries mentioned in the article, they simplify things to another level because they sort of remove the concept of
by have_faith 4y ago
You might like the atomic state management libraries mentioned in the article, they simplify things to another level because they sort of remove the concept of a store entirely. For example in Recoil I would do this:
export const isSidebarOpenAtom = atom({key: 'isSidebarOpen', default: false});
And in the component: (it mimics useState)
const [isSidebarOpen, setIsSidebarOpen] = useRecoilState(isSidebarOpenAtom);
and later...
setIsSidebarOpen(true)
Recoil will then re-render any component that relies on isSidebarOpen.
The only real boilerplate is having to specify keys for each atom, which I find a small price to pay for such simple global state.