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}
/>
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With