Skip to content Skip to sidebar Skip to footer

Reactjs 0.12 Target Container Is Not A Dom Element

I am very confused as to why I am getting this error in the console. I have read all the dos and as far as I know I am doing this right. On my page I have a
Copy

The defer attribute loads your script when the page has finished parsing, so even if you place your scripts into your index head, you will be sure the script is going to find all your elements because they will be there.

W3Schools defer

Update

The standard way is adding your scripts at the end of the body. They should load after the DOM is created, so the error should disappear because when you reach the DOM with your JavaScript, it is already there. defer is widely spread among browsers so you shouldn't have problems unless you are working with really old ones. You can use deferin order to arrange your code. It seems more intuitive to have your "dependencies" inside the header and your "code" inside the body.

Here you have a reference of where to use defer.

Solution 2:

The following piece of code tries to find the element with ID aisis-writer where it says document.getElementById('aisis-writer') but it's not able to find that on the page.

React.render(
  <AisisWriter />,
  document.getElementById('aisis-writer')
);

This may happen because

  1. JavaScript is executed before the line <div id="aisis-writer"></div>
  2. Or, you might have mis-spelt ID

Answer :

  1. Either you can place the React.render statements in window.onload
  2. Or, make sure, React.render appears only after <div id="aisis-writer"></div> on the page

Post a Comment for "Reactjs 0.12 Target Container Is Not A Dom Element"