UNPKG

jotai

Version:

👻 Next gen state management that will spook you

23 lines (20 loc) • 475 B
import { atom } from 'jotai'; function atomWithStore(store) { const baseAtom = atom(store.getState()); baseAtom.onMount = (setValue) => { const callback = () => { setValue(store.getState()); }; const unsub = store.subscribe(callback); callback(); return unsub; }; const derivedAtom = atom( (get) => get(baseAtom), (_get, _set, action) => { store.dispatch(action); } ); return derivedAtom; } export { atomWithStore };