question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document version 7.6.0 as a breaking change

See original GitHub issue

Is your feature request related to a problem? Please describe. There’s a breaking change that occurred after the release of version 7.6.0. I suspect it is related to https://github.com/react-hook-form/react-hook-form/pull/5069 where we add default values to register even if their corresponding fields are not rendered.

Previously, if we wanted to manually track fields that were not rendered in the HTML, we’d do something like this

const { register } = useForm({
  defaultValues: {
    manuallyTracked: true,
  },
});

useEffect(() => {
  register('manuallyTracked');
}, []);

// some functions modifying manuallyTracked state

return (
  <html-without-input-named-manually-tracked />
)

With the release of version 7.6.0, we no longer need to call register() to manually track fields which is great! However, doing so may result in unexpected bugs. In my case, an empty array was becoming an empty object.

Describe the solution you’d like Document this change and the fact we no longer need nor should call register() to manually register inputs.

Describe alternatives you’ve considered Downgrading the library version 😂

Additional context N/A

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mrluboscommented, Jun 4, 2021

Thanks for putting up all the investigation in the codesandboxes above, looks like it’s an edge case that I didn’t consider carefully enough for inputs that you want to update manually without an actual input. As I explained in the other issue, react hook form can’t predict if it’s a single input or array of inputs.

Here are a couple workaround for such use cases:

React.useEffect(() => {
  register("array", { value: getValues("array") });
}, [register, getValues]);
const { control, getValues, handleSubmit, register, watch } = useForm<
  FormValues
>({
  defaultValues,
  shouldUnregister: false
});
  • unregister input and then setValue to reset the entire field input.
unregistre('array');
setValue('array', [1,2,3]);

I hope the above can solve your problem. In the meantime, I will still try to figure a solution for custom array-like inputs (which doesn’t contain a real input) with auto register in the coming releases.

Thank you! I think the second approach with shouldUnregister will work as it should essentially be the behaviour prior to 7.6.0, right? Either way I tested it and it appears to work as expected. Thanks again

1reaction
mrluboscommented, Jun 4, 2021

Hey @bluebill1049, just wanted to provide you with an update. I was able to isolate the issue related to removing the register() call in my code. The bug was in my application, so nothing to fix in react-hook-form. Thank you for your fast responses and continued maintenance of this library!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Breaking Changes in Version 7 - RxJS
To workaround this issue there are two things you can do: 1. Rewrite your operators as outlined in the documentation, such that they...
Read more >
7.6.0 APM Breaking changes | APM Overview [7.15] - Elastic
The Elastic APM integration became generally available in 7.16 — see the APM Guide for updated documentation. Standalone APM Server users can see...
Read more >
760 Breaking Changes, Fundamentals - Our Umbraco
Go to docs.umbraco.com for documentation for Umbraco 9 and newer versions. ... This may be a breaking change for people relying on one...
Read more >
ODataLib changelog - OData - Microsoft Learn
Breaking changes it the library fall into one of four categories: Improved Performance. We will get better writer performance across the ...
Read more >
XCAF / B-Rep format changes in OCCT 7.6.0 - Unlimited 3D
Document written by a previous version of an application cannot be ... even small extensions required format compatibility breaking changes.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found