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.

Feature Request: Option to Keep Values of Unmounted Inputs in FormState (React Native)

See original GitHub issue

Is your feature request related to a problem? Please describe. When using Modals, especially the Modal component from React Native Paper, if the form elements are unmounted, then their values are removed from the formState.

Describe the solution you’d like Please give an option to allow for these values to persist when unmounted, as React Native has a lot of areas in which Dialog components simply return null to show that they are not displayed, rather than tweaking the styling.

Describe alternatives you’ve considered I’ve considered creating my own Modal components just to get around this issue, but honestly it would be nice to have the option regardless.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
bluebill1049commented, Apr 9, 2021

use shouldUnregister: false in v6.

What should be used in v7? I checked the notes but did not find any hint regarding this option?

v7 will no longer remove unmounted input value.

Are you sure? Version 7.0.4, which does not support shouldUnregister: false flag, still removes values when switching between tabs.

yes, unless you unmount the entire useForm.

Thanks, I was exactly expecting that. Have a look at the documentation it doesn’t directly point out that it is now the default behaviour. https://react-hook-form.com/faqs/#Howtoworkwithmodalortabforms

want to send a PR to correct that?

Sure, just tell me how. I’d mention that in the migration guide from v6 to v7 as well and extend Material UI Sandbox by an example with Checkbox and FormControlLabel, was struggling to figure it out on my own.

Fork the documentation repo, send us a PR with some better explanation and information for the change. 👍

0reactions
bartosz-szymanskicommented, Apr 9, 2021

use shouldUnregister: false in v6.

What should be used in v7? I checked the notes but did not find any hint regarding this option?

v7 will no longer remove unmounted input value.

Are you sure? Version 7.0.4, which does not support shouldUnregister: false flag, still removes values when switching between tabs.

yes, unless you unmount the entire useForm.

Thanks, I was exactly expecting that. Have a look at the documentation it doesn’t directly point out that it is now the default behaviour. https://react-hook-form.com/faqs/#Howtoworkwithmodalortabforms

want to send a PR to correct that?

Sure, just tell me how. I’d mention that in the migration guide from v6 to v7 as well and extend Material UI Sandbox by an example with Checkbox and FormControlLabel, was struggling to figure it out on my own.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Form's values get lost after hide / show form in render #1990
Describe the bug If I have Form with values and I want to show custom input to specify custom value and hide From,...
Read more >
useForm | React Hook Form - Simple React forms validation
This option allows you to configure validation strategy when inputs with ... to keep user interacted/dirty value and not remove any user errors...
Read more >
react-hook-form keep validating field after unregister
My simplified user case is that my form has two field firstname and lastname with a buttom that will unregister/register lastname and another...
Read more >
Managing React Forms in an easy and efficient way - Medium
The values of the fields are stored in a React state object throughout the handleChange method. ... React Hook Form comes with some...
Read more >
Input Components - React-admin - Marmelab
For instance, when setting the variant prop on a <TextInput> component, ... form state value --> format --> form input value (string).
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