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.

setValue()/reset() doesn't cause render inside Suspense

See original GitHub issue

Describe 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:

  1. https://codesandbox.io/s/admiring-morse-oq796?file=/src/App.js
  2. Observe the form field value says “flash of default” (the default value) instead of the value “from some API”.
  3. 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.)
  4. 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:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
bluebill1049commented, Jul 27, 2020

Yeah, it’s a bit unfortunate, we will have a proper solution once suspense is finalized.

1reaction
benswinburnecommented, Jul 27, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

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