{"record":{"id":"9b67d6f01ab08bcb","repo":"marmelab/react-admin","slug":"useeditcontroller-requires-a-non-empty-resource-pr","errorCode":null,"errorMessage":"useEditController requires a non-empty resource prop or context","messagePattern":"useEditController requires a non-empty resource prop or context","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/controller/edit/useEditController.ts","lineNumber":67,"sourceCode":"export const useEditController = <\n    RecordType extends RaRecord = any,\n    ErrorType = Error,\n>(\n    props: EditControllerProps<RecordType, ErrorType> = {}\n): EditControllerResult<RecordType, ErrorType> => {\n    const {\n        disableAuthentication = false,\n        id: propsId,\n        mutationMode = 'undoable',\n        mutationOptions = {},\n        queryOptions = {},\n        redirect: redirectTo = DefaultRedirect,\n        redirectOnError = DefaultRedirectOnError,\n        transform,\n    } = props;\n    const resource = useResourceContext(props);\n    if (!resource) {\n        throw new Error(\n            'useEditController requires a non-empty resource prop or context'\n        );\n    }\n    const { isPending: isPendingAuthenticated } = useAuthenticated({\n        enabled: !disableAuthentication,\n    });\n\n    const { isPending: isPendingCanAccess } = useRequireAccess<RecordType>({\n        action: 'edit',\n        resource,\n        enabled: !disableAuthentication && !isPendingAuthenticated,\n    });\n\n    const getRecordRepresentation = useGetRecordRepresentation(resource);\n    const translate = useTranslate();\n    const notify = useNotify();\n    const redirect = useRedirect();\n    const { id: routeId } = useParams<{ id?: string }>();","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/controller/edit/useEditController.ts#L49-L85","documentation":"useEditController drives the Edit view and must know which resource to query, redirect to, and authorize against. Like useCreateController, it resolves the resource via useResourceContext and throws when neither a `resource` prop nor a <Resource> context is available.","triggerScenarios":"Rendering <Edit> (or calling useEditController) outside any <Resource> context without a resource prop, or with an empty/undefined resource prop.","commonSituations":"Custom edit pages mounted via <CustomRoutes> instead of <Resource name=... edit=...>; reusing Edit components in modals or tabs outside the Admin tree; refactoring that accidentally dropped the resource prop from a wrapper.","solutions":["Pass resource explicitly: `<Edit resource=\"posts\" id={id}>` or `useEditController({ resource: 'posts', id })`.","Mount the component under the proper <Resource name=\"posts\" edit={...}> definition.","If using a custom route, ensure the wrapping <Resource> provides the name context.","Verify the resource variable is not empty due to a bad import or typo."],"exampleFix":"// before\n<CustomRoutes>\n  <Edit id={id} /> {/* no resource context */}\n</CustomRoutes>\n\n// after\n<CustomRoutes>\n  <Edit resource=\"posts\" id={id} />\n</CustomRoutes>","handlingStrategy":"validation","validationCode":"// Ensure resource presence before invoking the controller\nconst resource = props.resource ?? useResourceContext();\nif (!resource) throw new Error('Edit view rendered without a resource; pass resource=\"...\"');","typeGuard":"function hasResource(p: { resource?: string }): p is { resource: string } {\n  return typeof p.resource === 'string' && p.resource.length > 0;\n}","tryCatchPattern":"// Hook throws during render; guard before calling:\nif (!hasResource(props)) return <MissingResource />;\nconst controller = useEditController(props);","preventionTips":["Mount Edit views through <Resource name=\"...\" edit={...}>.","When using <CustomRoutes>, wrap content so a Resource context exists or pass resource explicitly.","Type-check wrapper components so the resource prop is required, not optional.","Test custom edit pages in isolation to catch missing context early."],"tags":["react-admin","controller","hooks","missing-context"],"backgroundTag":"missing-resource-context","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}