Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

MUI X Date Picker ignores the default value or shows the wrong format

ErrorThe picker is empty although a default value was passed

Short answer

MUI X pickers use values from your date library, such as dayjs(...), not plain strings. defaultValue only initializes the field; use value with onChange for a value you change later. The format prop uses the tokens of your adapter's library, and the adapter locale sets the language.

  • Applies to MUI X Date Pickers 7/8, Day.js, React 19
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print what you pass in. It should be an object from your date library (or null), not a string.

    console.log(typeof value, value)
  2. 2Match what you see, then jump to its fix

    1. 1The value you pass is a plain string such as '2022-04-17'The value is not a date-library objectFix
    2. 2The first render is right, later state changes never showdefaultValue is used where a controlled value is neededFix
    3. 3The field shows MM/DD/YYYY or the wrong languageThe format prop uses the wrong tokens, or no adapter locale is setFix

What does the error look like?

  • The picker is empty although a default value was passed
  • The date shows as MM/DD/YYYY and I need another order
  • The default value does not follow when the state changes

Cause 1 of 3

The value is not a date-library object

1Check

The base-concepts page builds every value with the library, for example dayjs('2022-04-17'), and shows an empty value as null.

grep -rn "defaultValue=\|value=" src/ | grep -i picker

2Fix

Wrap the string with the library that your adapter uses.

import dayjs from 'dayjs';

<DatePicker defaultValue={dayjs('2022-04-17')} />

3Verify

The field shows the date on load.

npm run dev

Confirmed by mui.com

Did this fix it?

Cause 2 of 3

defaultValue is used where a controlled value is needed

1Check

The docs say a valid value or defaultValue is used to initialize the component. For changing values the components expose value and onChange.

grep -rn "defaultValue" src/ | grep -i picker

2Fix

Hold the date in state and pass value and onChange.

const [value, setValue] = React.useState(dayjs('2022-04-17'));
<DatePicker value={value} onChange={(newValue) => setValue(newValue)} />

3Verify

Change the state from elsewhere and see the field follow.

npm run dev

Confirmed by mui.com

Did this fix it?

Cause 3 of 3

The format prop uses the wrong tokens, or no adapter locale is set

1Check

format tokens follow the library behind the adapter, so with Day.js use Day.js tokens. The default locale is English (United States) until you set adapterLocale.

grep -rn "format=\|adapterLocale" src/

2Fix

Set the format with your library's tokens and the locale on the provider.

import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import 'dayjs/locale/de';

<LocalizationProvider dateAdapter={AdapterDayjs} adapterLocale="de">
  <DatePicker format="YYYY/MM/DD" defaultValue={dayjs('2022-04-17')} />
</LocalizationProvider>

3Verify

The field renders in the new order.

npm run dev

Confirmed by mui.com

Did this fix it?

How do I stop it coming back?

  • Pick one date library and one adapter for the app.
  • Keep dates in state as library objects and convert to strings only at the API boundary.
  • Set format in one place, for example a shared wrapper component.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.