{"record":{"id":"a40ef91bcab676f4","repo":"marmelab/react-admin","slug":"you-must-provide-a-key-to-remove-an-item-from-the-a40ef9","errorCode":null,"errorMessage":"You must provide a key to remove an item from the store","messagePattern":"You must provide a key to remove an item from the store","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/store/useRemoveItemsFromStore.ts","lineNumber":29,"sourceCode":" * const ResetDatagridPrefs = () {\n *    const removeItems = useRemoveItemsFromStore();\n *\n *    const handleClick = () => {\n *        removeItems('datagrid.prefs');\n *    };\n *\n *    return <Button onClick={hancleClick}>Reset datagrid preferences</Button>;\n * }\n */\nexport const useRemoveItemsFromStore = (hookTimeKeyPrefix?: string | null) => {\n    const { removeItems } = useStoreContext();\n    return useCallback(\n        (keyPrefix?: string) => {\n            if (\n                typeof keyPrefix === 'undefined' &&\n                typeof hookTimeKeyPrefix === 'undefined'\n            ) {\n                throw new Error(\n                    'You must provide a key to remove an item from the store'\n                );\n            }\n            // @ts-ignore\n            return removeItems(keyPrefix ?? hookTimeKeyPrefix);\n        },\n        [removeItems, hookTimeKeyPrefix]\n    );\n};\n","sourceCodeStart":11,"sourceCodeEnd":39,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/store/useRemoveItemsFromStore.ts#L11-L39","documentation":"useRemoveItemsFromStore returns a callback that removes items from react-admin's global store under a key or key prefix. If neither an argument nor a hook-time key prefix is provided, there is nothing to target, so the hook throws instead of silently doing nothing.","triggerScenarios":"Calling the returned removeItems function with no argument (keyPrefix === undefined) while the hook was also created without a hookTimeKeyPrefix, e.g. const removeItems = useRemoveItemsFromStore(); removeItems();","commonSituations":"Developers wiring a 'clear stored preference' button and forgetting to pass the storage key, or refactoring useStore usage where the key was previously fixed at hook level and is now expected at call time.","solutions":["Pass the key (or key prefix) when calling the returned callback: removeItems('my.key').","Provide the key at hook level: useRemoveItemsFromStore('my.key') so call-time argument is optional.","If the key is dynamic, guard the call: if (key) removeItems(key)."],"exampleFix":"// before\nconst removeItems = useRemoveItemsFromStore();\nremoveItems(); // throws\n// after\nconst removeItems = useRemoveItemsFromStore('my.key');\nremoveItems(); // or removeItems('my.key')","handlingStrategy":"validation","validationCode":"if (typeof key !== 'string' || key.length === 0) {\n  throw new Error('removeItemsFromStore requires a key');\n}\nremoveItems(key);","typeGuard":"const hasKey = (k: unknown): k is string => typeof k === 'string' && k.length > 0;","tryCatchPattern":"try {\n  removeItems(key);\n} catch (e) {\n  console.error('Failed to remove store item', { key, e });\n}","preventionTips":["Always pass the storage key explicitly to the remove callback.","Bind the key at hook level when it is static: useRemoveItemsFromStore('my.key').","Add a lint rule or team convention that store keys are constants imported from one module."],"tags":["react-admin","store","missing-argument","hooks"],"backgroundTag":"missing-required-argument","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}