0

I'm getting this error on my Reactjs App. The point to note that I'm using the class instead of ID.

Uncaught Error: _registerComponent(...): Target container is not a DOM element.

This is my Js code

var React = require('react');
var ReactDOM = require('react-dom');
require('./style.css')

var App = require('./components/App')

ReactDOM.render( <App/>, document.getElementsByClassName('app') );

And my Html Code is

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>React App</title>
</head>
<body>
  <div class="app"></div>
</body>
</html>
Burhan Nasir
  • 644
  • 6
  • 14
  • 2
    Possible duplicate of [What do querySelectorAll, getElementsByClassName and other getElementsBy\* methods return?](http://stackoverflow.com/questions/10693845/what-do-queryselectorall-getelementsbyclassname-and-other-getelementsby-method) – Andreas May 15 '17 at 11:34
  • 1
    `document.getElementsByClassName('app')` returns a collection of all the elements, you need to use it like this: `document.getElementsByClassName('app')[0]` or use `id` instead of `class`, like this: `document.getElementById('app')` and define `id='app'` in html file. – Mayank Shukla May 15 '17 at 11:36

1 Answers1

1

It's because document.getElementsByClassName('app') returns array of elements and you need element itself.

Just use such code: document.getElementsByClassName('app')[0]

lunochkin
  • 684
  • 4
  • 17