{"record":{"id":"7b6cf5c0bc01e146","repo":"marmelab/react-admin","slug":"if-you-re-not-wrapping-the-selectinput-inside-a-re-7b6cf5","errorCode":null,"errorMessage":"If you're not wrapping the SelectInput inside a ReferenceInput, you must provide the choices prop","messagePattern":"If you're not wrapping the SelectInput inside a ReferenceInput, you must provide the choices prop","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-ui-materialui/src/input/SelectInput.tsx","lineNumber":181,"sourceCode":"        resource,\n        isFromReference,\n    } = useChoicesContext({\n        choices: choicesProp,\n        isLoading: isLoadingProp,\n        isFetching: isFetchingProp,\n        isPending: isPendingProp,\n        resource: resourceProp,\n        source: sourceProp,\n    });\n\n    if (source === undefined) {\n        throw new Error(\n            `If you're not wrapping the SelectInput inside a ReferenceInput, you must provide the source prop`\n        );\n    }\n\n    if (!isPending && !fetchError && allChoices === undefined) {\n        throw new Error(\n            `If you're not wrapping the SelectInput inside a ReferenceInput, you must provide the choices prop`\n        );\n    }\n\n    const getRecordRepresentation = useGetRecordRepresentation(resource);\n    const { getChoiceText, getChoiceValue, getDisableValue } = useChoices({\n        optionText:\n            optionText ??\n            (isFromReference ? getRecordRepresentation : undefined),\n        optionValue,\n        disableValue,\n        translateChoice: translateChoice ?? !isFromReference,\n        createValue,\n        createHintValue,\n    });\n    const { field, fieldState, id, isRequired } = useInput({\n        defaultValue,\n        parse,","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-ui-materialui/src/input/SelectInput.tsx#L163-L199","documentation":"SelectInput needs a list of options either passed directly via the `choices` prop or fetched by an enclosing ReferenceInput. If there is no pending fetch (isPending false) and no fetch error, and allChoices is still undefined, the component has no data source to render and throws this error.","triggerScenarios":"Rendering <SelectInput source=\"status\" /> with no choices prop and no ReferenceInput parent; passing choices={undefined} (e.g. from a variable that failed to initialize) once the fetch context reports it is not pending and no error occurred.","commonSituations":"Refactoring away a ReferenceInput but keeping the child SelectInput without inline choices; a data loader returning undefined silently so choices never arrive; forgetting that outside ReferenceInput the choices prop is mandatory.","solutions":["Pass the choices prop: <SelectInput source=\"status\" choices={[{ id: 1, name: 'One' }]} />.","Or wrap the input in <ReferenceInput source=\"...\" reference=\"...\"> to fetch choices automatically.","Verify whatever supplies choices is not undefined at render time (check the async load that builds the array)."],"exampleFix":"// before\n<SelectInput source=\"status\" />\n\n// after\n<SelectInput\n  source=\"status\"\n  choices={[\n    { id: 'draft', name: 'Draft' },\n    { id: 'published', name: 'Published' },\n  ]}\n/>","handlingStrategy":"validation","validationCode":"if (!choices && !insideReferenceInput) {\n  throw new Error('SelectInput requires a choices prop when not inside a ReferenceInput');\n}","typeGuard":"const hasChoices = <T,>(c: T[] | undefined): c is T[] =>\n  Array.isArray(c);","tryCatchPattern":null,"preventionTips":["Pass a literal or memoized choices array to standalone SelectInput","Check the async code that builds choices resolves to an array, not undefined","Use ReferenceInput for fetched related choices"],"tags":["react-admin","select-input","props","required-prop"],"backgroundTag":"missing-required-prop","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}