Prateek93a
Prateek93a

Reputation: 85

React component is not being displayed on browser, getting empty screen

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script><!--core react library-->
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script><!--help us inject react into the dom-->

<title>Document</title>
</head>
<body>
    <div id="app">
       

    </div>
    <script type="text/babel">

    class App extends React.Component{
       render(){
          
            return <div>Helo</div>
        }
    }
    let divapp=document.getElementById('app')
    ReactDom.render(<App />,divapp);
    </script>
</body>
</html>

I have tried everything I could, searched a lot of answers, but none of them helped, I just can't understand why my code is not working, I have cross checked me code with instructor's code, still i am having a blank screen before me, kindly help.

Upvotes: 3

Views: 1394

Answers (3)

Vivek Yadav
Vivek Yadav

Reputation: 39

<html lang="en">
  <head>
      <meta charset="UTF-8"/>
      <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
      <meta http-equiv="X-UA-Compatible" content="ie=edge"/>
      <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
      <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
  <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
  <script src="https://unpkg.com/[email protected]/babel.js"></script>
  <title>Document</title>


  </head>
  <body>
    <script type="text/babel">
            class App extends React.Component {
              render() {

                      return <div>Helo</div>
                  }
              }
              let divapp=document.getElementById('app')
              ReactDOM.render(<App />,divapp);
    </script>
    <div id="app">    
    </div>

  </body>
  </html>

Upvotes: 0

Prabu samvel
Prabu samvel

Reputation: 1223

I recommended you to follow the create-react-app approach which is very simple and easy way to start with reactjs.

Check this out.

https://reactjs.org/tutorial/tutorial.html

Under the :

Setup Option 2: Local Development Environment

Take a look on the :

Instructions for following along locally using your preferred text editor

Upvotes: 0

tam.dangc
tam.dangc

Reputation: 2032

  1. You need bable.js CDN in head tag too.

  2. ReactDOM not ReactDom

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script><!--core react library-->
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script><!--help us inject react into the dom-->
<script src="https://unpkg.com/[email protected]/babel.js"></script>
<title>Document</title>
</head>
<body>
    <div id="app">
       

    </div>
    <script type="text/babel">

    class App extends React.Component{
       render(){
          
            return <div>Helo</div>
        }
    }
    let divapp=document.getElementById('app')
    ReactDOM.render(<App />,divapp);
    </script>
</body>
</html>

Upvotes: 1

Related Questions