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],
                editFieldTypes

View on GitHub (pinned to 051f511bb0)

Solutions

  1. Pass resource explicitly: <EditGuesser resource="posts" />
  2. Register the component under <Resource name="posts" edit={EditGuesser} />
  3. 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

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


AI-assisted analysis of marmelab/react-admin@051f511bb0 (2026-08-30). Data as JSON: /api/errors/bab22d18390178de. Report an issue: GitHub.