{"record":{"id":"cd7e2fc64ef1cfee","repo":"marmelab/react-admin","slug":"uselistfiltercontext-must-be-used-inside-a-listfil","errorCode":null,"errorMessage":"useListFilterContext must be used inside a ListFilterContextProvider","messagePattern":"useListFilterContext must be used inside a ListFilterContextProvider","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/controller/list/useListFilterContext.ts","lineNumber":17,"sourceCode":"import { useContext } from 'react';\n\nimport { ListFilterContext, ListFilterContextValue } from './ListFilterContext';\n\n/**\n * Hook to read the list props from the ListFilterContext.\n *\n * Must be used within a <ListFilterContextProvider>.\n *\n * @returns {ListFilterContextValue} list controller props\n *\n * @see useListController for how it is filled\n */\nexport const useListFilterContext = (): ListFilterContextValue => {\n    const context = useContext(ListFilterContext);\n    if (!context) {\n        throw new Error(\n            'useListFilterContext must be used inside a ListFilterContextProvider'\n        );\n    }\n    return context;\n};\n","sourceCodeStart":1,"sourceCodeEnd":23,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/controller/list/useListFilterContext.ts#L1-L23","documentation":"useListFilterContext reads ListFilterContext, which is only populated by ListFilterContextProvider (set up by List/useListController internals). Outside such a provider the context is undefined and the hook throws.","triggerScenarios":"Calling useListFilterContext in a component not nested under <List>/<ListGuesser>/a manual <ListFilterContextProvider value={...}>.","commonSituations":"Custom filter UI components used on non-list pages; children extracted from a List and reused elsewhere; tests rendering the component bare.","solutions":["Nest the component inside a <List> page","In tests/stories, wrap with ListFilterContextProvider providing filter/setFilter","Use alternative state sources (props, store) if no list context exists"],"exampleFix":"// before\nexport const MyFilterButton = () => {\n  const { filter } = useListFilterContext(); // throws\n};\n// after\n// inside a List page:\n<List>\n  <MyFilterButton />\n</List>","handlingStrategy":"try-catch","validationCode":"const ctx = useContext(ListFilterContext);\nif (!ctx) return <DefaultFilterUI />; // avoid throwing hook path","typeGuard":"const hasFilterContext = (): boolean => useContext(ListFilterContext) !== null;","tryCatchPattern":"try { render(<MyFilter />); } catch (e) { if (String(e).includes('useListFilterContext')) { /* wrap in ListFilterContextProvider */ } }","preventionTips":["Only use the hook in components under <List>","Provide ListFilterContextProvider in tests with filter/setFilter","Keep filter components colocated with list pages"],"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"}