Reputation: 328
As per their Timepicker library i did following in React:
<TimePicker defaultValue={moment(dbTime1, format)} format={format}
onChange={time => setStartTime(moment(time).format(format))}/>
the state is:
const [dbTime1, setDbTime1] = useState("");
const [startTime, setStartTime] = useState(new Date());
Reading from database the string value 09:00 with:
setDbTime1(moment(timeWindowsData.din_times_for_rep[0].val));
The problem that the visual part is not displaying required to me 09:00 time, it just offering to select a time. If I do some modifications to the formats, etc - it gaves me various errors. Starting from invalid date and finishing with ipossibility to select a time, falling back to Date(), etc.
How can I store the variable and display the time in time field as default value?
It's working if i just drop the string there:
<TimePicker defaultValue={"09:00", format)} format={format}
onChange={time => setStartTime(moment(time).format(format))}/>
But I need that it must read from variable.
Upvotes: 1
Views: 2248