UNPKG

@knowmax/genericlist-core

Version:

Knowmax Generic list with basic CRUD support without any user interface implementation.

18 lines (17 loc) 769 B
import { jsx as _jsx } from "react/jsx-runtime"; import { createContext, useContext, useMemo } from 'react'; import { observer } from 'mobx-react-lite'; import { providerErrorMessage } from '../utils'; import { GenericListCache } from './GenericListCache'; const GenericListCacheContext = createContext(null); export const useGenericListCache = () => { const store = useContext(GenericListCacheContext); if (!store) { throw new Error(providerErrorMessage('GenericListCache')); } return store; }; export const GenericListCacheProvider = observer(({ children }) => { const genericlistcache = useMemo(() => new GenericListCache(10), []); return (_jsx(GenericListCacheContext.Provider, { value: genericlistcache, children: children })); });