UNPKG

ra-core

Version:

Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React

34 lines 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useRemoveItemsFromStore = void 0; const react_1 = require("react"); const useStoreContext_1 = require("./useStoreContext.cjs"); /** * Get a callback to remove all item with a certain key prefix from the store * * @example * import { useRemoveItemsFromStore } from 'react-admin'; * * const ResetDatagridPrefs = () { * const removeItems = useRemoveItemsFromStore(); * * const handleClick = () => { * removeItems('datagrid.prefs'); * }; * * return <Button onClick={hancleClick}>Reset datagrid preferences</Button>; * } */ const useRemoveItemsFromStore = (hookTimeKeyPrefix) => { const { removeItems } = (0, useStoreContext_1.useStoreContext)(); return (0, react_1.useCallback)((keyPrefix) => { if (typeof keyPrefix === 'undefined' && typeof hookTimeKeyPrefix === 'undefined') { throw new Error('You must provide a key to remove an item from the store'); } // @ts-ignore return removeItems(keyPrefix ?? hookTimeKeyPrefix); }, [removeItems, hookTimeKeyPrefix]); }; exports.useRemoveItemsFromStore = useRemoveItemsFromStore; //# sourceMappingURL=useRemoveItemsFromStore.js.map