ReferenceField

Follows a foreign key to another resource and renders a related field.

Installation

pnpm dlx shadcn@latest add @chelone/reference-field

Follows a foreign key to another resource and renders a related field.

Props

PropTypeDefaultDescription
childrenReactNode—Child field(s) rendered against the referenced record.
classNamestring—A class name applied to the link wrapper.
emptyReactNode—Rendered when the FK is null/undefined or its record is missing. A string is translated.
errorReactNode—Rendered when the reference lookup errors.
linkLinkToType—A `CreatePathType` (`"show"`/`"edit"`/…) or `false` to disable linking.
loadingReactNode—Rendered while the referenced record is loading.
recordRecordType—The record to read the FK off. Defaults to the ambient record.
referencestring—The referenced resource the FK points at (e.g. `"authors"`).
render(referenceRecord: UnknownRecord | undefined) => ReactNode—Render-prop alternative to `children`: receives the resolved referenced record. Called only after the reference resolves; loading, error and empty states use their respective props.
sourcestring—The FK field on the current record (e.g. `"author_id"`).