Updating a value that is in object format #3232
-
Hello! Quick question on how to handle a specific problem I'm dealing with. Currently in my app I am using a regular form with a multitude of handlers based on input. Right now i'm using a datepicker component that on change, returns two values -- v: value, and formatted: f. My question is, with the handleChange being built into formik, how would I update the date values to reflect my current state in initial values? Here is the date component, and the respective handleChange function I normally use.
Thanks for any help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
The short answer is you would generally only save one version from which all other versions could be recreated. For a date this might be an ISO formatted date, any string which could be parsed with date-fns, or an actual Date object. If the user can type in your input, though, you'll want to store a text based date-like string even if it isn't a valid date, to handle the user typing transient values. However, to help with your specific use case, it may be beneficial to recreate in a codesandbox and link it here. |
Beta Was this translation helpful? Give feedback.
The short answer is you would generally only save one version from which all other versions could be recreated. For a date this might be an ISO formatted date, any string which could be parsed with date-fns, or an actual Date object. If the user can type in your input, though, you'll want to store a text based date-like string even if it isn't a valid date, to handle the user typing transient values.
However, to help with your specific use case, it may be beneficial to recreate in a codesandbox and link it here.