{"record":{"id":"4211d8c71652f44e","repo":"marmelab/react-admin","slug":"useselectall-should-be-used-inside-a-resourceconte","errorCode":null,"errorMessage":"useSelectAll should be used inside a ResourceContextProvider or passed a resource prop","messagePattern":"useSelectAll should be used inside a ResourceContextProvider or passed a resource prop","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/controller/list/useSelectAll.tsx","lineNumber":49,"sourceCode":" *         <BulkDeleteButton />\n *     </BulkActionsToolbar>\n * );\n *\n * export const PostList = () => (\n *     <List>\n *         <Datagrid bulkActionsToolbar={<PostBulkActionsToolbar />}>\n *             ...\n *         </Datagrid>\n *     </List>\n * );\n */\nexport const useSelectAll = (\n    params: UseSelectAllParams\n): UseSelectAllResult => {\n    const { sort, filter, storeKey, disableSyncWithStore } = params;\n    const resource = useResourceContext(params);\n    if (!resource) {\n        throw new Error(\n            'useSelectAll should be used inside a ResourceContextProvider or passed a resource prop'\n        );\n    }\n    const dataProvider = useDataProvider();\n    const queryClient = useQueryClient();\n    const [, { select }] = useRecordSelection({\n        resource,\n        storeKey,\n        disableSyncWithStore,\n    });\n    const notify = useNotify();\n\n    const handleSelectAll = useEvent(\n        async ({\n            queryOptions = {},\n            limit = 250,\n        }: HandleSelectAllParams = {}) => {\n            const { meta, onSuccess, onError, ...otherQueryOptions } =","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/controller/list/useSelectAll.tsx#L31-L67","documentation":"useSelectAll selects all records of the current list by querying the dataProvider; it needs to know which resource to query. The resource normally comes from ResourceContext (set by ResourceContextProvider / <Resource>). The error is thrown when useResourceContext resolves to nothing, i.e. no resource in context and no `resource` param passed.","triggerScenarios":"Calling useSelectAll() outside a ResourceContextProvider and without a `resource` param: e.g. in a component used across multiple resources without context, in tests without a wrapping <ResourceContext.Provider>, or in a shared toolbar rendered outside the <Resource> tree.","commonSituations":"Building a custom 'select all' button placed outside the list's resource context; unit-testing the hook bare with renderHook; rendering components in a portal that escapes the resource context (portals do keep React context, but separate trees do not); using the hook in a standalone admin page.","solutions":["Pass resource explicitly: useSelectAll({ resource: 'posts' })","Or render the component inside the list/resource tree so ResourceContext provides the resource","In tests, wrap with <ResourceContext.Provider value=\"posts\">"],"exampleFix":"// before\nconst selectAll = useSelectAll();\n// after\nconst selectAll = useSelectAll({ resource: 'posts' });","handlingStrategy":"validation","validationCode":"const resource = useResourceContext();\nif (!resource) return null; // or pass { resource: 'posts' } to useSelectAll","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call the hook inside the list/resource tree where ResourceContext exists","Pass an explicit resource prop in shared/portal components and tests","Wrap test hooks with <ResourceContext.Provider value=\"...\">"],"tags":["react-admin","hooks","resource-context","missing-param"],"backgroundTag":"hook-used-outside-provider","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}