MUI X Date Picker ignores the default value or shows the wrong format
The picker is empty although a default value was passedShort 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.
Fix it fast
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)2Match what you see, then jump to its fix
- 1
The value you pass is a plain string such as '2022-04-17'The value is not a date-library objectFix - 2
The first render is right, later state changes never showdefaultValue is used where a controlled value is neededFix - 3
The field shows MM/DD/YYYY or the wrong languageThe format prop uses the wrong tokens, or no adapter locale is setFix
- 1
What does the error look like?
The picker is empty although a default value was passedThe date shows as MM/DD/YYYY and I need another orderThe 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 picker2Fix
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 devConfirmed by mui.com
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 picker2Fix
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 devConfirmed by mui.com
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 devConfirmed by mui.com
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fixWeb apps
Axios request is not cancelled when a React component unmounts
A cancelled request is logged as an error in the catch block
Axios cancels a request when you pass it an AbortSignal and later call abort() on its controller.
4 causes, each with a fix