I have a component build in ReactmyComponent.js
ReactDOM.render(
<MyComponent />,
document.getElementById('my-id')
);
In my Html, I want to render it twice, the HTML is as following:
<div id='my-id></div>
some html
<div id='my-id></div>
I want react render twice in this page, but it only render once for the second div. Is there anyway to render it twice?
Another option is to use a
class
to define elements to render in:Then in
js
:It looks like you want to render it in 2 different places, with non-React code in between. To do that, you'll want to give your
div
s different IDs:Then render the component to each
div
:You can't have the same
id
for two or more elements in HTML. Use differentid
sand call the
ReactDOM.render
separately for each id.You could do
Or You could also have two
div
tags with different idthen