UNPKG

ra-core

Version:

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

30 lines 1.11 kB
import { useCallback } from 'react'; import { useStoreContext } from './useStoreContext'; /** * 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>; * } */ export var useRemoveItemsFromStore = function (hookTimeKeyPrefix) { var removeItems = useStoreContext().removeItems; return useCallback(function (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 !== null && keyPrefix !== void 0 ? keyPrefix : hookTimeKeyPrefix); }, [removeItems, hookTimeKeyPrefix]); }; //# sourceMappingURL=useRemoveItemsFromStore.js.map