UNPKG

jotai

Version:

👻 Primitive and flexible state management for React

28 lines (27 loc) • 980 B
import { INTERNAL_buildStoreRev4 as INTERNAL_buildStore } from './internals.js'; let overriddenCreateStore; export function INTERNAL_overrideCreateStore(fn) { overriddenCreateStore = fn(overriddenCreateStore); } export function createStore() { if (overriddenCreateStore) { return overriddenCreateStore(); } return INTERNAL_buildStore(); } let defaultStore; export function getDefaultStore() { var _a; if (!defaultStore) { defaultStore = createStore(); if (process.env.NODE_ENV !== 'production') { ; (_a = globalThis).__JOTAI_DEFAULT_STORE__ || (_a.__JOTAI_DEFAULT_STORE__ = defaultStore); if (globalThis .__JOTAI_DEFAULT_STORE__ !== defaultStore) { console.warn('Detected multiple Jotai instances. It may cause unexpected behavior with the default store. https://github.com/pmndrs/jotai/discussions/2044'); } } } return defaultStore; }