{"record":{"id":"fe7a68f3374a0de4","repo":"marmelab/react-admin","slug":"listnoresults-must-be-used-inside-a-list-compo","errorCode":null,"errorMessage":"<ListNoResults> must be used inside a <List> component","messagePattern":"<ListNoResults> must be used inside a <List> component","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-ui-materialui/src/list/ListNoResults.tsx","lineNumber":18,"sourceCode":"import * as React from 'react';\nimport { CardContent, Typography } from '@mui/material';\nimport {\n    useGetResourceLabel,\n    useListContextWithProps,\n    useResourceContext,\n    useTranslate,\n} from 'ra-core';\n\nimport { Button } from '../button';\n\nexport const ListNoResults = (props: ListNoResultsProps) => {\n    const translate = useTranslate();\n    const resource = useResourceContext(props);\n    const { filterValues, setFilters } = useListContextWithProps(props);\n    const getResourceLabel = useGetResourceLabel();\n    if (!resource) {\n        throw new Error(\n            '<ListNoResults> must be used inside a <List> component'\n        );\n    }\n    return (\n        <CardContent>\n            <Typography variant=\"body2\">\n                {filterValues &&\n                setFilters &&\n                Object.keys(filterValues).length > 0 ? (\n                    <>\n                        {translate('ra.navigation.no_filtered_results', {\n                            resource,\n                            name: getResourceLabel(resource, 0),\n                            _: 'No results found with the current filters.',\n                        })}{' '}\n                        <Button\n                            onClick={() => setFilters({}, [])}\n                            label={translate('ra.navigation.clear_filters', {","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-ui-materialui/src/list/ListNoResults.tsx#L1-L36","documentation":"<ListNoResults> is the component <List> shows when the filtered list is empty. It derives the resource name via useResourceContext and needs it to build the 'No results found for X' label; when no resource is in context (and none passed as a prop) it throws.","triggerScenarios":"Rendering <ListNoResults> (or passing it as a custom `empty` component) outside a <List>/ListContext with no resource in context and no `resource` prop.","commonSituations":"Passing `<List empty={<ListNoResults/>}>` from a component rendered outside a ResourceContextProvider; typo in resource prop name; using ListNoResults as a generic 'empty state' widget in a non-list page.","solutions":["Use it inside a <List> so the resource context is available.","Pass the resource explicitly: `<ListNoResults resource=\"posts\" />`.","Wrap with `<ResourceContextProvider value=\"posts\">` if used outside a list."],"exampleFix":"// before\nexport const EmptyState = () => <ListNoResults />;\n// after\nexport const EmptyState = () => <ListNoResults resource=\"posts\" />;","handlingStrategy":"validation","validationCode":"const resource = useResourceContext();\nif (!resource) {\n  throw new Error('ListNoResults used outside a List: pass a resource prop');\n}","typeGuard":"const hasResource = (p: { resource?: string }): p is { resource: string } => typeof p.resource === 'string';","tryCatchPattern":null,"preventionTips":["Only use ListNoResults as the `empty` prop of <List>.","Pass resource explicitly when reusing it elsewhere.","Prefer useListContext-based custom empty states for non-list pages."],"tags":["react-admin","list","context","resource-context"],"backgroundTag":"missing-provider-context","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}