Quantcast
Channel: Render two components at two different ids- React - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Piotr Berebecki for Render two components at two different ids- React

$
0
0

Is this what you are after? http://codepen.io/PiotrBerebecki/pen/kkyYJv

The script tag to your js file should be put at the bottom of the body tag (below the targeted ids).

HTML:

<head>
  <title>React JS</title>
</head>

<body>
  <div id="app1"></div>
  <div id="app2"></div>

  <script src="/index.js"></script>
</body>

</html>

JS:

class Component1 extends React.Component {
  render() {
    return (
      <div>Hello React from Component 1</div>
    );
  }
}


class Component2 extends React.Component {
  render() {
    return (
      <div>Hello React from Component 2</div>
    );
  }
}


ReactDOM.render(
  <Component1 />,
  document.getElementById('app1')
);

ReactDOM.render(
  <Component2 />,
  document.getElementById('app2')
);

Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>