{"record":{"id":"f0f95b2bc6b6d846","repo":"marmelab/react-admin","slug":"usecreatecontroller-requires-a-non-empty-resource","errorCode":null,"errorMessage":"useCreateController requires a non-empty resource prop or context","messagePattern":"useCreateController requires a non-empty resource prop or context","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/controller/create/useCreateController.ts","lineNumber":59,"sourceCode":">(\n    props: CreateControllerProps<\n        RecordType,\n        MutationOptionsError,\n        ResultRecordType\n    > = {}\n): CreateControllerResult<RecordType> => {\n    const {\n        disableAuthentication,\n        record,\n        redirect: redirectTo,\n        transform,\n        mutationMode = 'pessimistic',\n        mutationOptions = {},\n    } = props;\n\n    const resource = useResourceContext(props);\n    if (!resource) {\n        throw new Error(\n            'useCreateController requires a non-empty resource prop or context'\n        );\n    }\n    const { isPending: isPendingAuthenticated } = useAuthenticated({\n        enabled: !disableAuthentication,\n    });\n    const { isPending: isPendingCanAccess } = useRequireAccess<RecordType>({\n        action: 'create',\n        resource,\n        enabled: !disableAuthentication && !isPendingAuthenticated,\n    });\n    const { hasEdit, hasShow } = useResourceDefinition(props);\n    const finalRedirectTo =\n        redirectTo ?? getDefaultRedirectRoute(hasShow, hasEdit);\n    const translate = useTranslate();\n    const notify = useNotify();\n    const redirect = useRedirect();\n    const { onSuccess, onError, meta, ...otherMutationOptions } =","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/controller/create/useCreateController.ts#L41-L77","documentation":"useCreateController builds the Create view controller and needs a resource name to know which data provider endpoint to call and how to build routes/redirections. It resolves the resource from the prop or ResourceContext via useResourceContext; if both are empty it throws this error.","triggerScenarios":"Rendering a <Create> component (or calling useCreateController directly) outside a <Resource> without a `resource` prop, or passing an empty-string resource prop.","commonSituations":"Building a custom create form displayed on a standalone route not registered under <Resource>; reusing Create in a modal outside the Admin router; forgetting the resource prop when wrapping useCreateController in a custom hook.","solutions":["Pass a non-empty resource prop: `<Create resource=\"posts\">` or `useCreateController({ resource: 'posts' })`.","Render the component inside the matching <Resource name=\"posts\"> so the context supplies the resource.","Register the page as a child of <Resource> in <Admin> rather than as an arbitrary custom route.","Check that you are not passing an empty string or undefined variable as resource (e.g. from a broken constant import)."],"exampleFix":"// before\nconst controller = useCreateController({});\n\n// after\nconst controller = useCreateController({ resource: 'posts' });","handlingStrategy":"validation","validationCode":"// Before rendering, ensure a resource is defined\nconst resource = props.resource ?? useResourceContext();\nif (!resource) throw new Error('Create 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":"// Render-time hook throws cannot be caught with try/catch inside the same\n// component; use an error boundary or pre-validate:\nif (!hasResource(props)) return <MissingResource resourceName={props.resource} />;\nconst controller = useCreateController(props);","preventionTips":["Pass resource=\"...\" whenever <Create> is used outside a <Resource>.","Prefer registering pages via <Resource name=\"...\" create={...}> over custom routes.","Avoid empty-string resource values from broken constants/imports.","Add an error boundary around custom admin pages to surface context mistakes 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"}