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

  1. Remove the emptyValue prop (the default '' works).
  2. If you need null stored on clear, keep emptyValue='' and add `parse={value => (value === '' ? null : value)}`.
  3. 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

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


AI-assisted analysis of marmelab/react-admin@051f511bb0 (2026-08-30). Data as JSON: /api/errors/9bdd27db642ec511. Report an issue: GitHub.