I am trying to create a very simple formik field for entering date and time. The requirements are:
- The field's value should be a JavaScript
Date. - The field should allow entering free-form text in an input field and convert it to a
Dateon blur events. - The field should display an error if the entered string cannot be converted to a valid date.
- If the form is reset, the field should show the initial value of the date.
While I was able to satisfy requirements 1 & 2 quite easily, I am having trouble with requirements 3 & 4. I think part of the problem is that I am storing the raw text of the input field in internal state. However, I can't think of another way. Is there a better pattern?
Here's my CodeSandbox. Please see the sections marked with "Issue 1" & "Issue 2"