{"record":{"id":"daf6382e09d5adae","repo":"marmelab/react-admin","slug":"usereferencefieldcontroller-missing-reference-pro","errorCode":null,"errorMessage":"useReferenceFieldController: missing reference prop. You must provide a reference, e.g. reference=\"posts\".","messagePattern":"useReferenceFieldController: missing reference prop\\. You must provide a reference, e\\.g\\. reference=\"posts\"\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/controller/field/useReferenceFieldController.ts","lineNumber":17,"sourceCode":"import { useMemo } from 'react';\nimport { UseQueryOptions } from '@tanstack/react-query';\n\nimport { RaRecord } from '../../types';\nimport { LinkToType, useGetPathForRecord } from '../../routing';\nimport { UseReferenceResult, useReference } from '../useReference';\nimport { useFieldValue } from '../../util';\n\nexport const useReferenceFieldController = <\n    ReferenceRecordType extends RaRecord = RaRecord,\n    ErrorType = Error,\n>(\n    options: UseReferenceFieldControllerOptions<ReferenceRecordType, ErrorType>\n): UseReferenceFieldControllerResult<ReferenceRecordType, ErrorType> => {\n    const { link, reference, queryOptions } = options;\n    if (!reference) {\n        throw new Error(\n            'useReferenceFieldController: missing reference prop. You must provide a reference, e.g. reference=\"posts\".'\n        );\n    }\n    const id = useFieldValue(options);\n    const referenceRecordQuery = useReference<ReferenceRecordType, ErrorType>({\n        reference,\n        id,\n        options: {\n            ...queryOptions,\n            enabled:\n                (queryOptions?.enabled == null ||\n                    queryOptions?.enabled === true) &&\n                id != null,\n        },\n    });\n\n    const path = useGetPathForRecord({\n        record: referenceRecordQuery.referenceRecord,","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/controller/field/useReferenceFieldController.ts#L1-L35","documentation":"useReferenceFieldController powers <ReferenceField> and needs to know which resource the reference points to (e.g. 'users'). The `reference` option is mandatory; if it is undefined at call time react-admin throws immediately so the field fails fast instead of issuing a query against an undefined resource.","triggerScenarios":"Using <ReferenceField> without the `reference` prop, or passing reference={undefined} because it comes from an undefined variable / missing object key; calling useReferenceFieldController directly with an options object lacking `reference`.","commonSituations":"Building a generic field wrapper that spreads props but forgets to forward `reference`; destructuring config where the resource name key is misspelled (refrence/referencedResource); dynamically generated reference fields where an empty array/undefined entry is passed through.","solutions":["Add the required reference prop to the field: <ReferenceField source=\"user_id\" reference=\"users\">.","If reference is dynamic, ensure the variable is defined and non-empty before rendering, or skip rendering the field while it is undefined.","Check spelling/prop forwarding when wrapping ReferenceField in a custom component so `reference` reaches the controller."],"exampleFix":"// before\n<ReferenceField source=\"user_id\" />\n// after\n<ReferenceField source=\"user_id\" reference=\"users\" link=\"show\">\n  <TextField source=\"name\" />\n</ReferenceField>","handlingStrategy":"validation","validationCode":"// guard before rendering a dynamic reference field\nif (!reference) return null; // or throw a descriptive error upstream\nreturn <ReferenceField source={source} reference={reference}>{children}</ReferenceField>;","typeGuard":"const hasReference = (props) =>\n  typeof props?.reference === 'string' && props.reference.length > 0;","tryCatchPattern":"try {\n  return <ReferenceField source={source} reference={reference} />;\n} catch (e) {\n  if (e.message.includes('missing reference prop')) {\n    console.error(`ReferenceField for ${source} rendered without reference`);\n    return null;\n  }\n  throw e;\n}","preventionTips":["Always pass an explicit reference prop on ReferenceField/ReferenceInput.","Type dynamic wrappers with TypeScript: reference: ResourceName (a required prop).","In generic field factories, validate the config object (reference key present and non-empty) before mapping to JSX.","Watch for typos like `refrence` that silently produce undefined."],"tags":["react-admin","reference-field","missing-prop","configuration"],"backgroundTag":"missing-required-prop","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}