Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove default selected date in DatePicker materialUI?

I am using date pickers in my project https://material-ui-pickers.dev/demo/datepicker, I have used a calendar with no year selection. When I open the calendar by clicking a textbox for the very first time, I don't want today's date to be selected and want it to be empty like this (show calendar). But if I select any date and close the calendar then the selected date should remain and it should not get cleared. Can anyone help me how do I achieve this??

const [selectedDate, handleDateChange] = useState(new Date());

<DatePicker
  disableToolbar
  variant="inline"
  label="Only calendar"
  helperText="No year selection"
  value={selectedDate}
  onChange={handleDateChange}
 />
like image 451
Dave Smith Avatar asked Oct 20 '25 10:10

Dave Smith


1 Answers

as you did not provide sample code, I think you have set the state variable default to current date, like as given in the example:

const [selectedDate, handleDateChange] = useState(new Date());

I would suggest to try by setting it to null eg:

const [selectedDate, handleDateChange] = useState(null);
like image 124
Tuhin Avatar answered Oct 23 '25 02:10

Tuhin