marmelab/react-admin · error · Error
emptyValue being set to null or undefined is not supported.
Error message
emptyValue being set to null or undefined is not supported. Use parse to turn the empty string into null.
What it means
<AutocompleteInput> uses a sentinel empty value to represent 'no selection'; setting `emptyValue` to null or undefined breaks that sentinel logic (an undefined/null emptyValue cannot be distinguished from real option values). The library forbids it and asks you to convert the empty input string to null/undefined via `parse` instead.
Source
Thrown at packages/ra-ui-materialui/src/input/AutocompleteInput.tsx:288
translate,
]
);
const selectedChoice = useSelectedChoice<
OptionType,
Multiple,
DisableClearable,
SupportCreate
>(field.value, {
choices: finalChoices,
// @ts-ignore
multiple,
optionValue,
});
useEffect(() => {
if (emptyValue == null) {
throw new Error(
`emptyValue being set to null or undefined is not supported. Use parse to turn the empty string into null.`
);
}
}, [emptyValue]);
useEffect(() => {
// eslint-disable-next-line eqeqeq
if (isValidElement(optionText) && emptyText != undefined) {
throw new Error(
`optionText of type React element is not supported when setting emptyText`
);
}
// eslint-disable-next-line eqeqeq
if (isValidElement(optionText) && inputText == undefined) {
throw new Error(`
If you provided a React element for the optionText prop, you must also provide the inputText prop (used for the text input)`);
}
if (View on GitHub (pinned to 051f511bb0)
Solutions
- Remove the emptyValue prop (the default '' works).
- If you need null stored on clear, keep emptyValue='' and add `parse={value => (value === '' ? null : value)}`.
- Ensure whatever feeds emptyValue is always a non-null string (e.g. `emptyValue={cfg.emptyValue ?? ''}`).
Example fix
// before
<AutocompleteInput source="category" emptyValue={null} />
// after
<AutocompleteInput
source="category"
parse={value => (value === '' ? null : value)}
/> Defensive patterns
Strategy: validation
Validate before calling
if (emptyValue == null) throw new Error('emptyValue must be a non-null string; use parse for null on clear'); Type guard
const hasValidEmptyValue = (p: { emptyValue?: unknown }): p is { emptyValue: string | number | boolean } => p.emptyValue != null; Prevention
- Omit emptyValue unless you specifically need a custom sentinel; default is ''.
- Use parse={v => v === '' ? null : v} to store null on clear instead of emptyValue={null}.
- Coalesce config-derived values: emptyValue={cfg.emptyValue ?? ''}.
When it happens
Trigger: Passing `emptyValue={null}` or an emptyValue variable that evaluates to null/undefined (e.g. from a constant or config that is unset) to <AutocompleteInput>; the useEffect check runs after render.
Common situations: Trying to store null in the form when the input is cleared; wiring emptyValue from a settings object that is missing; copying examples where emptyValue defaults to '' and overriding it badly.
Related errors
- useApplyInputDefaultValues: No fieldArrayInputControl passed
- <DateField> cannot have showTime and showDate false at the s
- optionText of type React element is not supported when setti
- If you provided a React element for the optionText prop, yo
- If you provided a React element for the optionText prop, yo
AI-assisted analysis of marmelab/react-admin@051f511bb0 (2026-08-30).
Data as JSON: /api/errors/9bdd27db642ec511.
Report an issue: GitHub.