-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issue: reset Field Array in combination with shouldUnregister: true
at useForm
level and Controller
doesn't give correct submission data
#10585
Comments
There are multiple
workaround use |
@bluebill1049 Thank you for the quick patch (as usual :-))! ⚡🩹
Uff, not so encouraging news this. 😬 Didn't it get loads of pushbacks from the community back then when moving from V6 to V7? I guess I still can also recall that our code didn't work properly anymore when not using But anyway, looking ahead, since we're using this small wrapper (custom hook) in our code along with const RenderFunction = ({ children }) => children(); function useControllerField({ name, control, rules, defaultValue }) {
const controller = useController({
name,
control,
rules,
defaultValue
});
return controller.field;
} ...would it work well if I also put function useControllerField({ name, control, rules, defaultValue, unregister }) {
const controller = useController({
name,
control,
rules,
defaultValue
});
useEffect(() => {
return () => {
unregister(name);
};
}, []);
return controller.field;
} I created a bit of experiment here (just try to play around with the "Submit" and "Toggle displayed" buttons): |
…)" This reverts commit 27ac86d.
Version Number
7.45.0
Codesandbox/Expo snack
https://codesandbox.io/s/react-hook-form-reset-usefieldarray-forked-n3xksj
Steps to reproduce
Expected behaviour
The submission data should be the reset values:
{ names: [{ firstName: 'Glenn' }, { firstName: 'Ania' }] }
instead of the default values:{ names: [{ firstName: 'John' }, { firstName: 'Glenn' }] }
.What browsers are you seeing the problem on?
Chrome
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: