1

Hi I am new in reactjs when i am running server.js file from terminal it show blank page on browser. The code of index.html file is:

 <!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8"/>
  <script src="https://cdnjs.cloudflare.com/ajax/babel-
core/5.8.23/browser.min.js"></script>
 <script 
src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react.js">
</script>
 <script 
 src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-
  dom.js"></script>
</head>
<body>
  <div id="app"></div>
 <script type="text/babel">
   ReactDOM.render(
  <h1>Hello React!</h1>,
   document.getElementById('app')
  );
 </script>
 </body>
</html>

Thanks in advance.

Sundeep Badhotiya
  • 810
  • 2
  • 9
  • 14

1 Answers1

1

This is a working example.

In your code, the wrong part is the CDN link to babel-core. You may always check your console when working with JS (on Google Chrome: Ctrl + shift + J on Windows, Cmd + Opt + J on IOS).

On the other hand, I thought this was a good opportunity to also introduce components (see ).

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>My First React Example</title>
  </head>
  <body>
    <div id="hello"></div>

    <script src="https://unpkg.com/react@15.0.0/dist/react.js"></script>
    <script src="https://unpkg.com/react-dom@15.0.0/dist/react-dom.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
    <script type="text/babel">
      var Greeting = React.createClass({
        render: function() {
          return (
            <p>Hello World</p>
          )
        }
      });

      ReactDOM.render(
        <Greeting/>,
        document.getElementById('hello')
      );
    </script>
  </body>
</html>