Why does register
not support defaultValue
?
#8392
Unanswered
timkindberg
asked this question in
Ideas
Replies: 1 comment 1 reply
-
because defaultValue belongs to inputs eg |
Beta Was this translation helpful? Give feedback.
1 reply
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.
-
Hello thank you for the awesome library!! We are migrating from Formik.
We are wondering though, why doesn't register support defaultValue? I am really loving defining all of my fields in their own isolated components, with validation logic and initial values all co-located. I'd rather not specify the defaultValue at the form level.
I've found that if I declare register in conjunction with resetField I can achieve a
defaultValue
. Like this:Code Sandbox:
https://codesandbox.io/s/useformstate-forked-t7b0gq?file=/src/App.js:472-657
Is there a problem with this approach? Or could the same thing be done internally to add support for
defaultValue
toregister
?In general I'm also wondering why not balance the APIs of
register
anduseController
. It seems it could be achieved and then have more predictable usage. Saw a discussion about this here: #4542Update: It even works when the registered field is watched, it has the defaultValue. But only if the watched field is mounted first. Is this restriction the reason that
defaultValue
was removed from register?Beta Was this translation helpful? Give feedback.
All reactions