marmelab/react-admin · error · Error
useNextPrevController was called outside of a ResourceContex
Error message
useNextPrevController was called outside of a ResourceContext and without a resource prop. You must set the resource prop.
What it means
useNextPrevController (used by NextPrevPageButtons / NavigationLink) determines the current resource to read the list params from the store. It resolves the resource from ResourceContext or the resource prop; when both are absent it throws.
Source
Thrown at packages/ra-core/src/controller/usePrevNextController.ts:128
): UsePrevNextControllerResult => {
const {
linkType = 'edit',
storeKey,
limit = 1000,
sort: initialSort = { field: 'id', order: SORT_ASC },
filter: permanentFilter = {},
filterDefaultValues = {},
queryOptions = {
staleTime: 5 * 60 * 1000,
},
} = props;
const record = useRecordContext<RecordType>(props);
const resource = useResourceContext(props);
const createPath = useCreatePath();
if (!resource) {
throw new Error(
`useNextPrevController was called outside of a ResourceContext and without a resource prop. You must set the resource prop.`
);
}
const [storedParams] = useStore<ListParams>(
storeKey || `${resource}.listParams`,
{
filter: filterDefaultValues,
order: initialSort.order,
sort: initialSort.field,
page: 1,
perPage: 10,
displayedFilters: {},
}
);
const dataProvider = useDataProvider();
const queryClient = useQueryClient();View on GitHub (pinned to 051f511bb0)
Solutions
- Pass the resource prop explicitly: <NextPrevPageButtons resource="posts" />
- Render the component inside the resource's context (inside a List/Show/Edit view or under <Resource>)
Example fix
// before <NextPrevPageButtons /> // outside ResourceContext // after <NextPrevPageButtons resource="posts" />
Defensive patterns
Strategy: validation
Validate before calling
if (!resource) throw new Error('NextPrevPageButtons requires resource or ResourceContext'); Type guard
const hasResource = (p: { resource?: string }): p is { resource: string } => typeof p.resource === 'string' && p.resource.length > 0; Try / catch
null
Prevention
- Pass resource explicitly when used outside list/show/edit views
- Keep such components inside react-admin's layout/context tree
- Check the hook docs for context requirements before custom mounting
When it happens
Trigger: Rendering <NextPrevPageButtons> (or calling usePrevNextController) outside a <Resource>/ListContext and without passing resource="posts"; using it in a component mounted before the ResourceContext provider.
Common situations: Adding navigation buttons to a custom page outside the react-admin layout; copy-pasting the component into a storybook story; forgetting the resource prop on a component nested under a non-Resource route.
Related errors
- useReferenceFieldController: missing reference prop. You mus
- <InfiniteList> was called outside of a ResourceContext and w
- useListController requires a non-empty resource prop or cont
- useShowController requires a non-empty resource prop or cont
- useShowController requires an id prop or a route with an /:i
AI-assisted analysis of marmelab/react-admin@051f511bb0 (2026-08-30).
Data as JSON: /api/errors/d5420b8a16163727.
Report an issue: GitHub.