UNPKG

mt-flowbite-react

Version:

Official React components built for Flowbite and Tailwind CSS

46 lines (45 loc) 1.36 kB
'use client'; import { jsx as _jsx } from "react/jsx-runtime"; import { createContext, useRef, useContext } from "react"; import { create, useStore } from 'zustand'; import { persist } from 'zustand/middleware'; export const createListItemSlice = (set, get, initState) => { const DEFAULT_PROPS = {}; return ({ ...DEFAULT_PROPS, // async loadDashConfig() { // const dashConfig = await loadDashConfig() // }, ...initState, }); }; export const createListItemStore = (initProps) => { return create()(persist((...a) => ({ ...createListItemSlice(...a), ...initProps, }), { name: 'listitem123', version: 1, skipHydration: true, onRehydrateStorage(state) { }, })); }; const Context = createContext(null); export function ContainerProvider({ children, ...props }) { const storeRef = useRef(); if (!storeRef.current) { storeRef.current = createListItemStore(props); } return (_jsx(Context.Provider, { value: storeRef.current, children: children })); } export function useContainerStore(selector, equals) { const store = useContext(Context); if (!store) throw new Error('Missing ContainerProvider'); if (selector) { return useStore(store, selector, equals); } else { return store; } }