Search code examples
typescriptmaterial-uimomentjs

MomentAdapter.js throwing a date.isUtc is not a function


I'm passing a date as an initial value for the MUI DatePicker, but I'm receiving the following error:

value.isUTC is not a function
./node_modules/@mui/x-date-pickers/AdapterMoment/AdapterMoment.js/AdapterMoment/this.getTimezone@

This is the date I'm parsing:

2024-03-12

This is how I'm parsing it:

const startDateIntervalFrom = startStringIntervalFrom ? moment(startStringIntervalFrom, searchFilterDateFormat).utc().toDate() : null;

I'm 100% sure it's parsing it correctly because I'm logging it on the console, so the date picker is receiving the correct date value

And this is my date picker

      <DatePicker
        label="From"
        value={start}
        onChange={handleStartDateChange}
      />

Solution

  • Found out that value accepts multiple date types. But you have to pass in the one you used in the Adapter that wraps around your date inputs. In my case I simply had to pass in a moment.Moment type of object