{"record":{"id":"cc9bd9edacf1d65f","repo":"marmelab/react-admin","slug":"cannot-use-listguesser-outside-of-a-resourcecont","errorCode":null,"errorMessage":"Cannot use <ListGuesser> outside of a ResourceContext","messagePattern":"Cannot use <ListGuesser> outside of a ResourceContext","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-ui-materialui/src/list/ListGuesser.tsx","lineNumber":118,"sourceCode":"    useEffect(() => {\n        setChild(null);\n    }, [resource]);\n\n    useEffect(() => {\n        if (data && data.length > 0 && !child) {\n            const inferredElements = getElementsFromRecords(\n                data,\n                listFieldTypes\n            );\n            const inferredChild = new InferredElement(\n                listFieldTypes.table,\n                null,\n                inferredElements\n            );\n            const inferredChildElement = inferredChild.getElement();\n            const representation = inferredChild.getRepresentation();\n            if (!resource) {\n                throw new Error(\n                    'Cannot use <ListGuesser> outside of a ResourceContext'\n                );\n            }\n            if (!inferredChildElement || !representation) {\n                return;\n            }\n\n            setChild(inferredChildElement);\n\n            const components = ['List']\n                .concat(\n                    Array.from(\n                        new Set(\n                            Array.from(representation.matchAll(/<([^/\\s>]+)/g))\n                                .map(match => match[1])\n                                .filter(component => component !== 'span')\n                        )\n                    )","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-ui-materialui/src/list/ListGuesser.tsx#L100-L136","documentation":"<ListGuesser> infers the list fields from the record data of the current resource. It reads the resource name from ResourceContext; the inference code checks `resource` and throws when it is undefined, because it cannot fetch sample records or build the child element without a resource.","triggerScenarios":"Rendering <ListGuesser> outside a <Resource> definition or outside the react-admin <Admin> context, e.g. in a standalone storybook route or a custom page that never sets ResourceContext.","commonSituations":"Using ListGuesser in a demo page outside <Admin>; forgetting to declare the resource in <Admin> so no ResourceContext provider wraps the route; rendering ListGuesser inside a custom layout before the resource context is set.","solutions":["Render <ListGuesser> only inside a <Resource name=\"...\" list={ListGuesser}> route within <Admin>.","If used standalone, wrap it: `<ResourceContextProvider value=\"posts\"><ListGuesser/></ResourceContextProvider>`.","Check the resource name is registered in <Admin> so its routes (and context) exist."],"exampleFix":"// before\nexport const MyList = () => <ListGuesser />;\n// after\nimport { ResourceContextProvider } from 'react-admin';\nexport const MyList = () => (\n  <ResourceContextProvider value=\"posts\">\n    <ListGuesser />\n  </ResourceContextProvider>\n);","handlingStrategy":"validation","validationCode":"const resource = useResourceContext();\nif (!resource) return <div>ListGuesser must be inside a Resource</div>;\nreturn <ListGuesser />;","typeGuard":"const inResourceContext = (v: string | undefined): v is string => typeof v === 'string' && v.length > 0;","tryCatchPattern":null,"preventionTips":["Use ListGuesser only inside <Resource list={ListGuesser}> under <Admin>.","For standalone demos, wrap with ResourceContextProvider.","Replace ListGuesser with an explicit <List> once inference is done (its intended lifecycle)."],"tags":["react-admin","listguesser","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"}