Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React.js Not Rendering?

So I have decided to start learning React.js, but am having problems rendering into the HTML

Cant seem to see whats wrong any help would be great both the HTML and JSX are below

(Note Full links to the react library are there just could post them here since Stack doesnt allow URL Shortners)

<!DOCTYPE html>
<html>

  <head>
    <link rel="stylesheet" href="style.css">
    <script src="react-15.2.1.js"></script>
    <script src="react-dom-15.2.1.js"></script>
    <script src="script.js"></script>
  </head>

  <body>
    <div id="root"></div>
  </body>

</html>

JSX

// Code goes here

var Button = React.createClass({
  render: function() {
    return ( < button > Go < /button>)
  }
});

React.render( < Button / > , document.getElementById("root"));

1 Answers

I have corrected your code, and placed the working result in this fiddle:

Your last line was wrong, it should be like this:

ReactDOM.render( < Button / > , document.getElementById("root"));
like image 191
Bowen Li Avatar answered Sep 15 '25 21:09

Bowen Li