{"record":{"id":"bab22d18390178de","repo":"marmelab/react-admin","slug":"editguesser-was-called-outside-of-a-resourcecont","errorCode":null,"errorMessage":"<EditGuesser> was called outside of a ResourceContext and without a resource prop. You must set the resource prop.","messagePattern":"<EditGuesser> was called outside of a ResourceContext and without a resource prop\\. You must set the resource prop\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ra-ui-materialui/src/detail/EditGuesser.tsx","lineNumber":56,"sourceCode":"            redirect={redirect}\n            transform={transform}\n            disableAuthentication={disableAuthentication}\n        >\n            <EditGuesserView {...rest} />\n        </EditBase>\n    );\n};\n\nexport interface EditGuesserProps<RecordType extends RaRecord = any>\n    extends Omit<EditProps<RecordType>, 'children'> {}\n\nexport const EditGuesserView = <RecordType extends RaRecord = any>(\n    props: EditGuesserProps<RecordType>\n) => {\n    const resource = useResourceContext(props);\n\n    if (!resource) {\n        throw new Error(\n            `<EditGuesser> was called outside of a ResourceContext and without a resource prop. You must set the resource prop.`\n        );\n    }\n\n    const { record } = useEditContext();\n    const [child, setChild] = useState<ReactNode>(null);\n    const { enableLog = process.env.NODE_ENV === 'development', ...rest } =\n        props;\n\n    useEffect(() => {\n        setChild(null);\n    }, [resource]);\n\n    useEffect(() => {\n        if (record && !child) {\n            const inferredElements = getElementsFromRecords(\n                [record],\n                editFieldTypes","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-ui-materialui/src/detail/EditGuesser.tsx#L38-L74","documentation":"EditGuesser inspects the data provider and record to generate an edit form, so it must know which resource to guess for. It resolves the resource from context or prop; if both are absent, the library throws to avoid guessing on an undefined resource.","triggerScenarios":"Rendering <EditGuesser> without a `resource` prop and outside any ResourceContext (e.g. direct route usage without <Resource>); useResourceContext(props) returns null.","commonSituations":"Using EditGuesser on custom routes not registered under <Resource>; prototypes where resources weren't declared; forgetting the prop when extracting the guesser to a standalone page.","solutions":["Pass resource explicitly: <EditGuesser resource=\"posts\" />","Register the component under <Resource name=\"posts\" edit={EditGuesser} />","Wrap usage in <ResourceContextProvider resource=\"posts\">"],"exampleFix":"// before\n<Route path=\"/posts/:id\" element={<EditGuesser />} />\n// after\n<Route path=\"/posts/:id\" element={<EditGuesser resource=\"posts\" />} />","handlingStrategy":"validation","validationCode":"const resource = props.resource ?? useContext(ResourceContext);\nif (!resource) return <Redirect to=\"/\" />;\nreturn <EditGuesser resource={resource} />;","typeGuard":"const hasResource = (p: { resource?: string }): p is { resource: string } => typeof p.resource === 'string' && p.resource.length > 0;","tryCatchPattern":null,"preventionTips":["Always pass resource to guessers used on custom routes","Register guessers through <Resource edit={EditGuesser}> so context is set","Gate guesser routes behind a check for a valid resource param"],"tags":["react-admin","missing-prop","resource-context","guesser"],"backgroundTag":"missing-required-resource-context","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}