I'm getting this error in my React App:
App.js
:
render() {
return(
<div>
<Header />
<div id="body">
<MainContainer />
</div>
</div>
);
}
MainContainer.js
:
functComp1() {
ReactDOM.render(<OtherComponent />, document.getElementById('body');
}
render() {
return (
<div className="row">
<div><a onClick={this.functComp1}>Component1</a></div>
<div><a onClick={this.functComp2}>Component2</a></div>
<div><a onClick={this.functComp3}>Component3</a></div>
</div>
);
}
When I click a Component link it works perfectly but the console shows this message:
Replacing React-rendered children with a new root component. If you intended to update the children of this node, you should instead have the existing children update their state and render the new components instead of calling ReactDOM.render.
How can I prevent this warning from appearing?