I have a material ui date picker field that I want to allow the user to leave blank if not required.
However, ReactJS does not allow me to leave this field as empty or null, as I get the console error of:
Uncaught RangeError: Invalid time value at Date.toISOString
<LocalizationProvider dateAdapter={AdapterDateFns}>
<MobileDatePicker label={"Date From"}
inputFormat="dd/MM/yyyy"
closeOnSelect={true}
value={datefrom ?? null}
minDate={new Date()}
views={['day']}
onChange={(newValue) => {
setDateFrom(format(newValue, 'MM/dd/yyyy'));
if (dateto == '') {
setDateTo(format(newValue, 'MM/dd/yyyy'));
} }}
renderInput={(params) => <TextField variant="outlined" {...params} fullWidth />} />
</LocalizationProvider>
How do I force the item to save a timestamp field as empty/null?