0

I am using MUI DatePicker. When I try to get target.value I have this error enter image description here

Here is my code

<LocalizationProvider dateAdapter={AdapterDayjs}>
  <DatePicker
    className={Turn.picker}
    defaultValue={date}
    InputProps={{ endAdornment: <CustomIconButton /> }}
    onChange={handleDateChange}
  />
</LocalizationProvider>

and this is my hangleDataChange function

const [date, setDate] = useState();
const handleDateChange = (event) => {
  setDate(event.target.value);
};

1 Answer 1

0

The error you're encountering is because the handleDateChange function is not receiving the expected event object.

Instead of event.target.value, you should be directly using the value provided by the onChange function of the DatePicker. The function should look like this:

const handleDateChange = (newValue) => {
  setDate(newValue);
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.