setValue()/reset() doesn't cause render inside Suspense
See original GitHub issueDescribe the bug
When setting default values from an async source as you’ve suggested by @bluebill1049 on Spectrum and on Github, the best way is to use reset or setValue. When the form is wrapped in <Suspense> and the values are retrieved asynchronously then passed to setValue
, the form does not rerender.
To Reproduce Steps to reproduce the behavior:
- https://codesandbox.io/s/admiring-morse-oq796?file=/src/App.js
- Observe the form field value says “flash of default” (the default value) instead of the value “from some API”.
- If you want to turn suspense off, change suspense: true to suspense: false in the code and refresh the sandbox (as changing the code causes hot reload to rerender the components.)
- With suspense off, see “from some API” instead of “flash of default”
Expected behavior The form fields to refresh after using setValue() or reset() inside a Suspense component.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
React hooks form: reset or setValue when updating form first ...
So I want to update the form with values coming from customer , so I have done this: useEffect(() => { let isMounted...
Read more >React Hooks cheat sheet: Best practices with examples
Without an array dependency, the effect function will be run after every single render.
Read more >Documentation - SolidJS · Reactive Javascript Library
A declarative, efficient and flexible JavaScript library for building user interfaces.
Read more >Suspense for Data Fetching (Experimental) - React
We wait for all data to come back with Promise.all() inside fetchProfileData , so now we can't render profile details until the posts...
Read more >Writing Resilient Components - Overreacted
If you use a color prop inside a Button component, you'll see the value ... often causes problems for the upcoming Concurrent Rendering...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah, it’s a bit unfortunate, we will have a proper solution once suspense is finalized.
Yeah unfortunately the whole point is to create a hook where I can just set up a remote form with autosaving all in one place. As soon as I hoist part of the functionality it goes back to gluing bits together (this app has a lot of forms too 😄 ). Probably going to have to make a HoC to group it together instead of a hook which is a bit of a shame but alas it is what it is as I’m stumped as to why a ref doesn’t work.
Thanks for having a look.