Controller with useFieldArray re-rendering all fields #9043
-
React Hook Form works perfectly with normal input fields, but when we use MUI TextField inside Controller it is re-rendering for each time when append, delete, and other useFieldArray methods are triggered.When we comment the fieldState prop it will not cause any issue but the form needs the error prop I tried with both Controller and useController gives the same result. ### I want these text fields not to re-render when adding, or deleting rows like the normal input. https://codesandbox.io/s/react-hook-form-with-usefieldarray-up60vy Using Normal Input Using Controller
Using useController Hook
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
@lokeshk12510 : Could you please share video of highlighting updates with normal inputs that is working perfectly as your expectation and then the video with MUI TextField ? I've tried with MUI TextField in your codesandbox with formState error and without formState error but it looks like the same to me. |
Beta Was this translation helpful? Give feedback.
-
@lokeshk12510 : Your custom Controller component (like ControlledInput, ControlledInput2, InputField) is watching on field state to perform a re-rendering if there is an error related to its field. When using native You can apply Working demo for ControlledInput2: https://codesandbox.io/s/react-hook-form-with-usefieldarray-forked-lmvjei?file=/src/components/ControlledInput2.jsx |
Beta Was this translation helpful? Give feedback.
-
@lokeshk12510 : It seems you are misunderstanding re-rendering of React component with react-hook-form and also how highlight updates on React devtools works.
|
Beta Was this translation helpful? Give feedback.
-
@leapful : Thank you for your reply. |
Beta Was this translation helpful? Give feedback.
@lokeshk12510 : It seems you are misunderstanding re-rendering of React component with react-hook-form and also how highlight updates on React devtools works.
when looping from useFieldArray every input field under for loop will re-render, Ok then why this description field is re-rendering when adding a new row
=> Whenever the "fields" from "useFieldArray" changes (append, prepend, move, remove, ...), it will trigger a re-rendering on App.js (where hook "useFieldArray" is called) therefore your new
<ControlledInput2 name="desc" control={control} />
also re-rendered. This is how React Functional component works with hooks.Also, in our first comment, you said the native input field is not …