DEV Community

Discussion on: How to Dynamically Render Components in React

Collapse
 
devhammed profile image
Hammed Oyedele

Not so efficient because the components are still rendered but not in the DOM, a better option is to use function that return the component in the mapping then call the function in map callback.

Collapse
 
andyrewlee profile image
Andrew Lee

Good catch! Just noticed the typo in my componentMapping. Before it was something like

const componentMapping = {
  Navbar1: <Navbar1 />
}

I just changed it to this so we render in the map callback.

const componentMapping = {
  Navbar1
}
Collapse
 
devhammed profile image
Hammed Oyedele

Oh...I get it now.
😁😁😁