The error value.isValid is not a function is one of the most common stumbling blocks developers encounter when implementing the MUI X Date and Time Pickers. In real terms, it typically appears suddenly during development or, worse, in production logs, halting the date selection workflow entirely. Understanding why this happens requires a look at how MUI handles date validation internally and, more importantly, how the value prop is expected to be structured across different versions of the library Still holds up..
This article provides a complete walkthrough to diagnosing and resolving this specific error, covering the differences between MUI v5 and v6, the role of adapter libraries, and the correct patterns for controlling picker state Small thing, real impact. Which is the point..
Understanding the Root Cause
At its core, the error value.In real terms, isValid is not a function indicates a type mismatch. But the MUI DatePicker component expects the value prop to be an instance of a specific date object provided by your chosen adapter library (such as dayjs, date-fns, Luxon, or Moment. js). On top of that, these adapter instances possess an . isValid() method that MUI uses internally to verify the integrity of the date before rendering or updating the UI No workaround needed..
When you pass a raw JavaScript Date object, a string (like "2023-10-25"), a timestamp (number), or null/undefined without proper handling, the component attempts to call .Day to day, isValid() on that raw value. Since native JavaScript Date objects do not have an isValid method (they have getTime() or toString()), the JavaScript engine throws the TypeError.
The Golden Rule: The value prop must be a valid adapter instance (e.g., dayjs()), or null/undefined (representing an empty state). It must never be a raw Date, string, or number directly Easy to understand, harder to ignore..
Version Differences: MUI v5 vs. v6
The way this error manifests and the strictness of the type checking have evolved significantly between major versions.
MUI v5 (Legacy @mui/lab and early @mui/x-date-pickers)
In v5, the component was somewhat more forgiving in specific scenarios but notoriously inconsistent. Now, if you passed a raw Date object, it might occasionally render but fail during interaction (opening the picker, changing views). The internal validation logic often tried to coerce the value, but the .isValid() check on the raw object remained a primary failure point The details matter here..
MUI v6 (Current @mui/x-date-pickers / @mui/x-date-pickers-pro)
MUI v6 introduced stricter TypeScript definitions and a more rigid internal architecture. Think about it: the component now assumes the developer is managing the adapter instance correctly. The localization and validation logic relies heavily on the adapter's API. Practically speaking, if you are migrating from v5 to v6, this error often surfaces because v6 removed implicit coercion fallbacks that existed in v5. You must ensure your state management creates adapter instances immediately upon parsing input data.
The Adapter Pattern: Why It Exists
MUI X Date Pickers are "adapter-agnostic.Worth adding: " They do not ship with a date manipulation engine. Instead, they rely on LocalizationProvider to inject a specific adapter (Day.js, date-fns, Luxon, Moment) Took long enough..
// Correct Setup Pattern
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { DatePicker } from '@mui/x-date-pickers/DatePicker';
import dayjs from 'dayjs';
export default function MyPicker() {
const [value, setValue] = React.useState(null); // State holds dayjs instance or null
return (
setValue(newValue)}
renderInput={(params) => }
/>
);
}
In this pattern, value is guaranteed to be a dayjs object (or null). On top of that, calling value. isValid() works perfectly.
Common Scenarios Triggering the Error
1. Initializing State with Raw Data from an API
This is the number one cause. Your backend returns an ISO string: "2024-01-15T00:00:00.000Z". You put this directly into useState But it adds up..
Incorrect:
const [date, setDate] = useState(apiResponse.date); // String
// or
const [date, setDate] = useState(new Date(apiResponse.date)); // Native Date
Correct:
import dayjs from 'dayjs';
// Initialize with adapter instance immediately
const [date, setDate] = useState(() => apiResponse.date ? dayjs(apiResponse.
// Or inside useEffect if fetching
useEffect(() => {
fetchData().then(res => setDate(dayjs(res.date)));
}, []);
2. Uncontrolled Components with defaultValue
Even if you are not controlling the value prop (using defaultValue instead), the same rule applies. defaultValue expects an adapter instance.
Incorrect:
Correct:
3. Form Library Integration (React Hook Form, Formik)
When integrating with form libraries, the value passed to the Controller or Field component often comes from the form state. If the form is initialized with raw data (e.g., defaultValues from an API), the picker receives a string/Date Took long enough..
Solution: Transform data before it enters the form state, or use the form library's setValue / watch mechanisms with a transformer It's one of those things that adds up..
// React Hook Form Example
const { control, watch, setValue } = useForm({
defaultValues: {
// Transform API string to dayjs instance immediately
birthDate: initialData.birthDate ? dayjs(initialData.birthDate) : null,
},
});
// Inside render
(
field.onChange(val)} // Pass adapter instance back
renderInput={(params) => (null); // TypeScript
// or
const [value, setValue] = useState(null); // JS
Ensure your onChange handler handles the null case when a user clears the picker:
onChange={(newValue) => setValue(newValue)} // newValue is null if cleared
Deep Dive: The Validation Flow
To fully grasp the error, visualize the internal render cycle of <DatePicker />:
-
Props Received: Component receives
valueprop. -
Internal Validation: It calls
utils.isValid(value)(whereutilsis the adapter wrapper) It's one of those things that adds up.. -
Adapter Delegation:
utils.isValid()essentially executesvalue.isValid()Worth keeping that in mind. No workaround needed.. -
**Crash
-
Crash: If
valueis a string (e.g.,"2024-01-01"), calling.isValid()on it fails because strings lack this method, leading to a runtime error.
This sequence underscores why the adapter instance is non-negotiable—it’s the only object with the required methods the component relies on.
Conclusion
The "isValid is not a function" error is a clear signal that the date picker expects a rich date object, not a primitive value. js, or Luxon for all date handling—whether in state, props, or form integrations—you ensure compatibility with the component's internal logic. Consider this: embracing this pattern not only prevents runtime errors but also unlocks the full power of date manipulation utilities, leading to more dependable and maintainable applications. By consistently using an adapter like Dayjs, Moment.Always remember: when working with specialized date pickers, treat adapter instances as the universal currency for date values.