UNPKG

mt-flowbite-react

Version:

Official React components built for Flowbite and Tailwind CSS

53 lines (52 loc) 1.88 kB
"use strict"; 'use client'; Object.defineProperty(exports, "__esModule", { value: true }); exports.useContainerChildStore = exports.ContainerChildProvider = exports.createListItemStore = exports.createListItemSlice = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const zustand_1 = require("zustand"); const middleware_1 = require("zustand/middleware"); const createListItemSlice = (set, get, initState) => { const DEFAULT_PROPS = {}; return ({ ...DEFAULT_PROPS, // async loadDashConfig() { // const dashConfig = await loadDashConfig() // }, ...initState, }); }; exports.createListItemSlice = createListItemSlice; const createListItemStore = (initProps) => { return (0, zustand_1.create)()((0, middleware_1.persist)((...a) => ({ ...(0, exports.createListItemSlice)(...a), ...initProps, }), { name: 'listitem123', version: 1, skipHydration: true, onRehydrateStorage(state) { }, })); }; exports.createListItemStore = createListItemStore; const Context = (0, react_1.createContext)(null); function ContainerChildProvider({ children, ...props }) { const storeRef = (0, react_1.useRef)(); if (!storeRef.current) { storeRef.current = (0, exports.createListItemStore)(props); } return ((0, jsx_runtime_1.jsx)(Context.Provider, { value: storeRef.current, children: children })); } exports.ContainerChildProvider = ContainerChildProvider; function useContainerChildStore(selector, equals) { const store = (0, react_1.useContext)(Context); if (!store) throw new Error('Missing ContainerChildProvider'); if (selector) { return (0, zustand_1.useStore)(store, selector, equals); } else { return store; } } exports.useContainerChildStore = useContainerChildStore;