UNPKG

@zedux/react

Version:

A Molecular State Engine for React

24 lines (23 loc) 863 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useEcosystem = void 0; const atoms_1 = require("@zedux/atoms"); const react_1 = require("react"); const utils_1 = require("../utils"); /** * Get the current ecosystem controlling atom usages in this component. * * If an ecosystem has been provided via an `<EcosystemProvider>` above the * current component, `useEcosystem()` returns a reference to the provided * ecosystem. * * If no ecosystem has been provided, `useEcosystem()` returns the global * ecosystem (creating it if it hasn't been created yet). * * Returns an Ecosystem class instance. */ const useEcosystem = () => { const id = (0, react_1.useContext)(utils_1.ecosystemContext); return (0, atoms_1.getEcosystem)(id) || (0, atoms_1.createEcosystem)({ id }); }; exports.useEcosystem = useEcosystem;