jotai
Version:
👻 Next gen state management that will spook you
33 lines (25 loc) • 1 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('jotai')) :
typeof define === 'function' && define.amd ? define(['exports', 'jotai'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.jotaiRedux = {}, global.jotai));
})(this, (function (exports, jotai) { 'use strict';
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, action) {
store.dispatch(action);
});
return derivedAtom;
}
exports.atomWithStore = atomWithStore;
Object.defineProperty(exports, '__esModule', { value: true });
}));