mt-flowbite-react
Version:
Official React components built for Flowbite and Tailwind CSS
44 lines (43 loc) • 1.29 kB
JavaScript
'use client';
import { jsx as _jsx } from "react/jsx-runtime";
import { createContext, useContext, useRef } from 'react';
import { create, useStore } from 'zustand';
import { persist } from 'zustand/middleware';
export const createListItemSlice = (set, get, initState) => {
const DEFAULT_PROPS = {};
return {
...DEFAULT_PROPS,
...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 ListItemProvider({ children, ...props }) {
const storeRef = useRef();
if (!storeRef.current) {
storeRef.current = createListItemStore(props);
}
return _jsx(Context.Provider, { value: storeRef.current, children: children });
}
export function useListItemStore(selector, equals) {
const store = useContext(Context);
if (!store)
throw new Error('Missing ListItemProvider');
if (selector) {
// eslint-disable-next-line
return useStore(store, selector, equals);
}
else {
return store;
}
}