marmelab/react-admin · error
<EditGuesser> was called outside of a ResourceContext and wi
Error message
<EditGuesser> was called outside of a ResourceContext and without a resource prop. You must set the resource prop.
What it means
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.
Source
Thrown at packages/ra-ui-materialui/src/detail/EditGuesser.tsx:56
redirect={redirect}
transform={transform}
disableAuthentication={disableAuthentication}
>
<EditGuesserView {...rest} />
</EditBase>
);
};
export interface EditGuesserProps<RecordType extends RaRecord = any>
extends Omit<EditProps<RecordType>, 'children'> {}
export const EditGuesserView = <RecordType extends RaRecord = any>(
props: EditGuesserProps<RecordType>
) => {
const resource = useResourceContext(props);
if (!resource) {
throw new Error(
`<EditGuesser> was called outside of a ResourceContext and without a resource prop. You must set the resource prop.`
);
}
const { record } = useEditContext();
const [child, setChild] = useState<ReactNode>(null);
const { enableLog = process.env.NODE_ENV === 'development', ...rest } =
props;
useEffect(() => {
setChild(null);
}, [resource]);
useEffect(() => {
if (record && !child) {
const inferredElements = getElementsFromRecords(
[record],
editFieldTypesView on GitHub (pinned to 051f511bb0)
Solutions
- Pass resource explicitly: <EditGuesser resource="posts" />
- Register the component under <Resource name="posts" edit={EditGuesser} />
- Wrap usage in <ResourceContextProvider resource="posts">
Example fix
// before
<Route path="/posts/:id" element={<EditGuesser />} />
// after
<Route path="/posts/:id" element={<EditGuesser resource="posts" />} /> Defensive patterns
Strategy: validation
Validate before calling
const resource = props.resource ?? useContext(ResourceContext);
if (!resource) return <Redirect to="/" />;
return <EditGuesser resource={resource} />; Type guard
const hasResource = (p: { resource?: string }): p is { resource: string } => typeof p.resource === 'string' && p.resource.length > 0; Prevention
- 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
When it happens
Trigger: Rendering <EditGuesser> without a `resource` prop and outside any ResourceContext (e.g. direct route usage without <Resource>); useResourceContext(props) returns null.
Common situations: 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.
Related errors
- <BulkDeleteButton> components should be used inside a <Resou
- <CreateButton> components should be used inside a <Resource>
- <DeleteButton> components should be used inside a <Resource>
- <DeleteWithConfirmButton> components should be used inside a
- <DeleteWithUndoButton> components should be used inside a <R
AI-assisted analysis of marmelab/react-admin@051f511bb0 (2026-08-30).
Data as JSON: /api/errors/bab22d18390178de.
Report an issue: GitHub.