reactjs - Is it OK to use React.render() multiple times in the DOM? -
i want use react add components multiple times throughout dom. this fiddle shows i'm looking do, , doesn't throw errors. here's code:
html:
<div id="container"> <!-- element's contents replaced first component. --> </div> <div id="second-container"> <!-- element's contents replaced second component. --> </div>
js:
var hello = react.createclass({ render: function() { return <div>hello {this.props.name}</div>; } }); react.render(<hello name="world" />, document.getelementbyid('container')); react.render(<hello name="second world" />, document.getelementbyid('second-container'));
i've seen this question , i'm afraid doing above, i'll risking having react components interfere each other. answer question suggests using server-side rendering isn't option me i'm using django server-side.
on other hand, maybe i'm doing ok because have 1 instance of react library mounted (as opposed multiple components calling own instance of react)?
is way of using multiple dom instances ok way use react?
yes, fine call react.render
multiple times on same page. you've suggested, react library loaded once, each call react.render
create new component instance independent of others. (in fact, such situation not uncommon on sites in process of transitioning react, portions of page generated using react.render
, others not.)
Comments
Post a Comment