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.

Question: ReactDOM render call in useEffect delayed until first update

See original GitHub issue

Do you want to request a feature or report a bug?

A question, maybe a bug but more likely a misunderstanding on my side.

What is the current behavior?

Calling ReactDOM.render from within a useEffect won’t actually render to the dom unless an update is triggered from anywhere else within the entire react app.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn’t have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:

See: https://codesandbox.io/s/jl02nrqznw

What is the expected behavior?

After the RendersAnotherRoot component is initially rendered, the useEffect function is called and then the subsequent ReactDOM.render call renders the separate react root.

Note: Uncommenting the setCount update from within the RendersAnotherRootWithUpdate component will then render the content from both useEffect render calls.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

react 16.8.1 react-dom 16.8.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
gaearoncommented, Feb 14, 2019
1reaction
gaearoncommented, Feb 13, 2019

Canary 0.0.0-0e4135e8c should have the fix. This will make it into 16.8.2.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strange behavior of React hooks: delayed data update
The state update is asynchronous so if you are using Hooks you can use useEffect to be notified after an update. Here is...
Read more >
How the useEffect Hook Works (with Examples) - Dave Ceddia
When you call useEffect in your component, this is effectively queuing or scheduling an effect to maybe run, after the render is done....
Read more >
Hooks API Reference - React
useDeferredValue accepts a value and returns a new copy of the value that will defer to more urgent updates. If the current render...
Read more >
React state not updating immediately? - Daggala
You update the state and you expect it to happen immediately but it doesn't. It might seems like the state update isn't updating...
Read more >
How To Call Web APIs with the useEffect Hook in React
You'll load information when a component first mounts and save customer inputs with an API. You'll also refresh data when a user makes...
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