Pattern: ISO-string date fields to avoid Date-object reactivity issues #2151
Unanswered
jiji-hoon96
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Has anyone else run into Date-object reactivity issues with TanStack Form's date fields? Closed issue #1712 ("isDefaultValue not updating when changing date field") surfaces a class of problem that comes from comparing Date instances by reference rather than value.
I work on Kalyx (a headless React DatePicker) and we took a different approach there — wanted to share the pattern in case it fits as a recipe or documentation note here.
The pattern
Use ISO 8601 UTC strings as the field value type, never Date objects:
Two things it gets you:
defaultValue === currentValueis plain string comparison, soisDefaultValue/isPristinetrack correctly. The class of bug inisDefaultValuenot updating when changing date field #1712 doesn't apply.z.iso.datetime()validates without a Date round-trip, and you can serialize to JSON without manual.toISOString()calls.Asking
examples/react/? There's asimpleexample but no date-field one specifically, and date-related issues seem to converge on this same shape.Happy to put together a self-contained
examples/react/date-fields-iso/example. Kalyx works as the picker because of the ISO contract, but the pattern is library-agnostic — anything that emits strings would do.Beta Was this translation helpful? Give feedback.
All reactions