Maria Jane Maria Jane - 2 months ago 7
React JSX Question

getElementById reference error using react

https://jsbin.com/nisetupaqa/edit?html,js,console,output

var App = React.createClass({
render(){
return(
<h1>Hello world</h1>
)
}
})

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


What's wrong? Couldn't get a hello world to work, I got error of
"ReferenceError: getElementById is not defined

Answer

This should work :

class App extends React.Component {
  handleClick(e){
    alert("Clicked");
  }
  render(){
      return(
         <h1 onClick={this.handleClick.bind(this)}>Hello world</h1>
    )
  }
}

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