marmelab/react-admin · error · Error
useListController requires a non-empty resource prop or cont
Error message
useListController requires a non-empty resource prop or context
What it means
useListController (backing <List>) resolves the resource name from a `resource` prop or ResourceContext. If neither yields a non-empty string, it throws because it cannot build the dataProvider call.
Source
Thrown at packages/ra-core/src/controller/list/useListController.ts:69
props: ListControllerProps<RecordType, ErrorType> = {}
): ListControllerResult<RecordType, ErrorType> => {
const {
debounce = 500,
disableAuthentication = false,
disableSyncWithLocation = false,
exporter = defaultExporter,
filter,
filterDefaultValues,
perPage = 10,
queryOptions = {},
sort = defaultSort,
storeKey,
} = props;
const resource = useResourceContext(props);
const { meta, ...otherQueryOptions } = queryOptions;
if (!resource) {
throw new Error(
`useListController requires a non-empty resource prop or context`
);
}
if (
filter &&
(isValidElement(filter) ||
(Array.isArray(filter) && filter.some(isValidElement)))
) {
throw new Error(
'useListController received a React element as `filter` props. If you intended to set the list filter elements, use the `filters` (with an s) prop instead. The `filter` prop is internal and should not be set by the developer.'
);
}
const { isPending: isPendingAuthenticated } = useAuthenticated({
enabled: !disableAuthentication,
});
const { isPending: isPendingCanAccess } = useRequireAccess<RecordType>({View on GitHub (pinned to 051f511bb0)
Solutions
- Pass resource explicitly: <List resource="posts">
- Ensure the component is rendered within a <Resource name="posts"> context
- Fix the route/param that supplies a dynamic resource name
- Guard rendering: only render <List> when resource is truthy
Example fix
// before export const MyListView = () => <List />; // after export const MyListView = () => <List resource="posts" />; // or guard if (!resource) return null;
Defensive patterns
Strategy: validation
Validate before calling
const resource = props.resource ?? useResourceContext();
if (!resource) throw new Error('useListController needs a resource');
return <List resource={resource} />; Type guard
const hasResource = (p: { resource?: string }): p is { resource: string } =>
typeof p.resource === 'string' && p.resource.length > 0; Try / catch
try { return <List resource={maybeResource} />; } catch (e) { if (String(e).includes('non-empty resource')) { return <EmptyState />; } } Prevention
- Pass resource explicitly on custom pages
- Validate route params before rendering list pages
- Add ResourceContextProvider in tests/stories
- Search codebase for bare `<List />` usages
When it happens
Trigger: Rendering <List> outside a <Resource> without `resource` prop; passing resource={undefined} (e.g. from a missing route param); empty string resource.
Common situations: Custom pages using List directly; dynamic routes where :resource is missing; renaming resources and forgetting a prop; storybook/tests without ResourceContext.
Related errors
- <InfiniteList> was called outside of a ResourceContext and w
- useShowController requires a non-empty resource prop or cont
- useNextPrevController was called outside of a ResourceContex
- useUnique: missing resource prop or context
- <Show> requires either a `render` prop or `children` prop
AI-assisted analysis of marmelab/react-admin@051f511bb0 (2026-08-30).
Data as JSON: /api/errors/471da470a4a5325b.
Report an issue: GitHub.