jotai
Version:
👻 Next gen state management that will spook you
30 lines (22 loc) • 697 B
JavaScript
Object.defineProperty(exports, '__esModule', { value: true });
var jotai = require('jotai');
function atomWithStore(store) {
var baseAtom = jotai.atom(store.getState());
baseAtom.onMount = function (setValue) {
var callback = function callback() {
setValue(store.getState());
};
var unsub = store.subscribe(callback);
callback();
return unsub;
};
var derivedAtom = jotai.atom(function (get) {
return get(baseAtom);
}, function (get, _set, update) {
var newState = typeof update === 'function' ? update(get(baseAtom)) : update;
store.setState(newState, true);
});
return derivedAtom;
}
exports.atomWithStore = atomWithStore;
;