How to trigger onChange handler of a controlled component with the form's defaultValues? #10366
Unanswered
danielmarcano
asked this question in
Q&A
Replies: 1 comment 1 reply
-
|
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
-
Hi there,
Is there a way to trigger the
onChange
handler of a controlled component with the form'sdefaultValues
?Here's a codesandbox that explains my doubt with the minimum code possible. In there, you will notice that the
console.log
is never shown, which is what has triggered my question.The use-case I have is the following:
I have a parent component with a form state, and sub-components that each represent a step of said form
In one of my sub-components, I set a default
timeZone
within thedefaultValues
object, this way:onChange
handler:Just like in the codesandbox, my controlled component does get set to the correct
defaultValue
, but theonChange
handler is never called.By writing this question, it has occurred to me that I can simply add
getCurrentBrowserTimeZone()
as the default value of my form state, right when I create it, within the parent component, and simply remove the function from these default values. This would work, but I still want to leave this question here in case someone can find its response helpful.Beta Was this translation helpful? Give feedback.
All reactions