Debugging Unnecessary Re-Renders: Combining isDirty Flag and useFormState Hook in a Form #11426
Unanswered
derekbking
asked this question in
Q&A
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.
-
I believe I may have found a bug in the library, but I'm wanting to get some feedback incase I'm overlooking something.
I have a simple scenario where I mark the input labels of dirty fields red. I can do so without causing re-renders to the parent component like so:
I also have some logic to create a red border if the form is dirty. This code appropriately only re-renders the App when the isDirty state changes. However, I started to see unnecessary re-renders of the App when I have both the red label logic and the isDirty logic implemented. Every time I dirty a field I will get an additional re-render of the App even though the isDirty flag was already true. This seems odd to me because the formState should be wrapped in a proxy according the the docs. I have not subscribed to dirtyFields within the App component, so I do not expect re-renders when the dirtyFields property changes. It feels that the useFormState hook shares a proxy with the original form state causing the App component to subscribe to dirtyFields even though I did not explicitly do so in the App component.
CodeSandbox Demo
Beta Was this translation helpful? Give feedback.
All reactions