What i understood is you have 2 components and you want is to render 1 component at a time. so it's better to use conditional rendering and render only one component using ReactDOM.render()
for example
import React from 'react'
import ReactDOM from 'react-dom';
import Component1 from 'somewhere'
import Component2 from 'somewhere'
let renderedComponent;
if (certain condition to meet) {
renderedComponent = <Component1/>
} else {
renderedComponent = <Component2/>
}
ReactDOM.render(renderedComponent, document.getElementById('root'));
Another way
// check condition here and assign its value
// eg: let renderComponent1 = ( condition to check )
let renderComponent1 = true
let renderComponent2 = false
ReactDOM.render(
<div>
{renderedComponent1 && <Component1 />}
{renderedComponent2 && <Component2 />}
</div>
, document.getElementById('root'));
This will only render <Component1 />
and if you want to only render <Component2/>
then set renderComponent2
to true and renderComponent1
to false.
Setting true
to both renderComponent1
and renderComponent2
variables will render both component and setting false
will not render any component
I hope this is what you need.