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.

Why only one component can be render at root div?

See original GitHub issue

I called two render methods to same root div .

RenderDOM.render( < Navigation /> ,document.getElementById(' root ')); 
RenderDOM.render( < App /> ,document.getElementById(' root '));

And what i get rendered on my screen is only a App component. Just want to know that the one render method override the previous render method?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
bvaughncommented, Dec 25, 2019

To clarify: the original question seems to be why the following code only ends up showing App rather than both Navigation and App.

RenderDOM.render( < Navigation /> ,document.getElementById(' root ')); 
RenderDOM.render( < App /> ,document.getElementById(' root '));

The answer is that the second call to render replaces the first. If you want to render both Navigation and App, then you should render them both in the same call using either a “fragment” or an array:

RenderDOM.render(
  <React.Fragment>
    <Navigation />
    <App />
  </React.Fragment>,
  document.getElementById(" root ")
);

Hope this helps!

1reaction
bvaughncommented, Dec 25, 2019

Seems like this issue has been answered now?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why can components only return one node in ReactJS? (Is ...
Currently, in a component's render, you can only return one node; if you have, say, a list of divs to return, you must...
Read more >
Rendering Elements - React
Rendering an Element into the DOM​​ We call this a “root” DOM node because everything inside it will be managed by React DOM....
Read more >
How to Use One Component to Render Many HTML ...
Before React 16.2, you could render only a single DOM node inside the render method. Now you can render multiple DOM nodes.
Read more >
How to Easily Render Multiple Elements in React - ITNEXT
In Vue and React, we can only render one element. Even if we have multiple elements to render, there can only be a...
Read more >
Why does react only allow one DOM element to be rendered?
InnerHTML requires a root element and in many implementations requires the provided html to be a structurally complete snippet. Structurally complete requires ...
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