March 2019
Intermediate to advanced
534 pages
14h 52m
English
There are a couple of improvements that could be made to the preceding example. For starters, you could have a DatePicker component that hides some of the details about turning a TextField component into something that picks dates. Further, it would be nice if the new DatePicker component supported actual Date instances as values.
First, you'll need a utility function that can format Date instances into the string format expected by the TextField component when it's being used as a date picker:
function formatDate(date) { const year = date.getFullYear(); const month = date.getMonth() + 1; const day = date.getDate(); return [ year, month < 10 ? `0${month}` : month, day < 10 ? `0${day}` : day ].join('-');}
The formatDate()
Read now
Unlock full access