{"record":{"id":"b490c18bf33d84cd","repo":"marmelab/react-admin","slug":"uselistpaginationcontext-must-be-used-inside-a-lis","errorCode":null,"errorMessage":"useListPaginationContext must be used inside a ListPaginationContextProvider","messagePattern":"useListPaginationContext must be used inside a ListPaginationContextProvider","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/controller/list/useListPaginationContext.ts","lineNumber":21,"sourceCode":"import {\n    ListPaginationContext,\n    ListPaginationContextValue,\n} from './ListPaginationContext';\n\n/**\n * Hook to read the list pagination controller props from the ListPaginationContext.\n *\n * Must be used within a <ListPaginationContext> (e.g. as a descendent of <List>\n * or <ListBase>).\n *\n * @returns {ListPaginationContextValue} list controller props\n *\n * @see useListController for how it is filled\n */\nexport const useListPaginationContext = (): ListPaginationContextValue => {\n    const context = useContext(ListPaginationContext);\n    if (!context) {\n        throw new Error(\n            'useListPaginationContext must be used inside a ListPaginationContextProvider'\n        );\n    }\n    return context;\n};\n","sourceCodeStart":3,"sourceCodeEnd":27,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/controller/list/useListPaginationContext.ts#L3-L27","documentation":"useListPaginationContext reads ListPaginationContext, populated only by ListPaginationContextProvider inside list controllers. Called elsewhere, the context is undefined and the hook throws to fail fast.","triggerScenarios":"Calling useListPaginationContext in a component not nested under <List>/a manual <ListPaginationContextProvider value={...}> — e.g. custom pagination used on a standalone page.","commonSituations":"Reusing the default Pagination component outside a list; tests without the provider; components moved out of a List after refactoring.","solutions":["Render the pagination component inside a <List> (or ListContextProvider-backed tree)","In tests, wrap with ListPaginationContextProvider with page/perPage/setPage values","Pass page/perPage callbacks as props when the component is used standalone"],"exampleFix":"// before\nexport const StandalonePager = () => {\n  const { page } = useListPaginationContext(); // throws\n};\n// after\n<List perPage={25}>\n  <StandalonePager />\n</List>","handlingStrategy":"try-catch","validationCode":"const ctx = useContext(ListPaginationContext);\nif (!ctx) return <StaticPagination page={1} />;","typeGuard":"const hasPaginationContext = (): boolean => useContext(ListPaginationContext) !== null;","tryCatchPattern":"try { render(<Pagination />); } catch (e) { if (String(e).includes('useListPaginationContext')) { /* nest inside List */ } }","preventionTips":["Only render Pagination components inside a List tree","Wrap with ListPaginationContextProvider in tests (page, perPage, setPage)","Pass explicit page/perPage props for standalone use"],"tags":["react-admin","react-context","missing-provider"],"backgroundTag":"hook-called-outside-provider","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}