marmelab/react-admin · error
useSelectAll should be used inside a ResourceContextProvider
Error message
useSelectAll should be used inside a ResourceContextProvider or passed a resource prop
What it means
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.
Source
Thrown at packages/ra-core/src/controller/list/useSelectAll.tsx:49
* <BulkDeleteButton />
* </BulkActionsToolbar>
* );
*
* export const PostList = () => (
* <List>
* <Datagrid bulkActionsToolbar={<PostBulkActionsToolbar />}>
* ...
* </Datagrid>
* </List>
* );
*/
export const useSelectAll = (
params: UseSelectAllParams
): UseSelectAllResult => {
const { sort, filter, storeKey, disableSyncWithStore } = params;
const resource = useResourceContext(params);
if (!resource) {
throw new Error(
'useSelectAll should be used inside a ResourceContextProvider or passed a resource prop'
);
}
const dataProvider = useDataProvider();
const queryClient = useQueryClient();
const [, { select }] = useRecordSelection({
resource,
storeKey,
disableSyncWithStore,
});
const notify = useNotify();
const handleSelectAll = useEvent(
async ({
queryOptions = {},
limit = 250,
}: HandleSelectAllParams = {}) => {
const { meta, onSuccess, onError, ...otherQueryOptions } =View on GitHub (pinned to 051f511bb0)
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">
Example fix
// before
const selectAll = useSelectAll();
// after
const selectAll = useSelectAll({ resource: 'posts' }); Defensive patterns
Strategy: validation
Validate before calling
const resource = useResourceContext();
if (!resource) return null; // or pass { resource: 'posts' } to useSelectAll Prevention
- 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="...">
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- useCanAccess must be used inside a <Resource> component or p
- useCreateController requires a non-empty resource prop or co
- useEditController requires a non-empty resource prop or cont
- useArrayInput must be used inside an ArrayInputContextProvid
- useSimpleFormIterator must be used inside a SimpleFormIterat
AI-assisted analysis of marmelab/react-admin@051f511bb0 (2026-08-30).
Data as JSON: /api/errors/4211d8c71652f44e.
Report an issue: GitHub.