Replies: 4 comments 2 replies
-
Can you try to provide |
Beta Was this translation helpful? Give feedback.
-
MUI Dialog component is using Popper.js + React Portal to position content element, therefore after being rendered, the DOM element will be mutated again for positioning and caused conflict on setting data of react-hook-form because react-hook-form will rely on mounted state to handle form values. If you want to reset data on useEffect, make sure it happens after the position change, a workaround is using Working demo: https://codesandbox.io/s/elated-albattani-lj2v8x?file=/src/AddOrEditModal.js |
Beta Was this translation helpful? Give feedback.
-
To conclude, wenn working with Dialog components there are multiple options:
Although there is no optimal solution for this problem, I hope this will help somebody out. |
Beta Was this translation helpful? Give feedback.
-
Wow, this discussion is from 2023! I just opened an issue about this. If the workarounds above don't cut it, we can also set a |
Beta Was this translation helpful? Give feedback.
-
Version Number
7.45.0
Codesandbox/Expo snack
https://codesandbox.io/s/nice-dew-4fr479
Steps to reproduce
Expected behaviour
The input fields should be cleared as well.
However if you type in something into the textfields and then reset the fields, the values will be reverted to the original values passed to the dialog component. It seems like the first values that are passed via
form.reset
become the new default values, although I have passed{ keepDefaultValues: true}
as an option parameter. In this example there are no default values passed touseForm
, but theController
component that wrapps the text fields has thedefaultValue
prop set tonull
.Please note that the elements of the Dialog component are not mounted until the dialog is open by default.
What browsers are you seeing the problem on?
Chrome
Relevant log output
No response
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions