0

I'm trying/playing around with React and have some issues that I cant seem to find on google and there's nothing in my console log? Can anybody tell me why this isn't working? React and ReactDOM libraries are included...

HTML

<div id="app"></div>

JS

class App extends React.Component{
  render(){
    return (
       <div>Hello</div>
    )
  }
}

ReactDOM.render(App, document.getElementById('app'));
1
  • 1
    ReactDOM.render(<App />, document.getElementById('app')); For rendering App component has to rendered using jsx syntax, as <App />. Commented Aug 26, 2018 at 13:57

3 Answers 3

2

You should render JSX element:

ReactDOM.render(<App />, document.getElementById('app'));
Sign up to request clarification or add additional context in comments.

Comments

0

First You have to import the component:

import App from "./App";

Then render the component like <App />:

ReactDOM.render(<App />, document.getElementById("app"));

Comments

0

You need to use:

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

You can't render a react component class, you need to render an element

Just so you understand why this is the case:

When you use JSX to create an element your build process will transform it from

<App />

to

h("App", {}, null)

But If you just pass the class this conversion will not happen

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.