Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React not defined on Codepen

I am trying to run a basic React Component in CodePen (I enabled Babel and I used React.Component ) but it still does not render. In the console it shows React not defined. I also took some already rendered code from another person and it does not work!!

class App extends React.Component {
  constructor(props){
    super(props);

    this.state = {
      term : ""

    }

    this.handleChange=this.handleChange.bind(this)

  }

  handleChange(event){
    let term = event.target.value;
    this.setState({term})

  }


  render() {
    return (
      <div className="App">
        <input value={this.state.term}  onChange={this.handleChange} />
        {this.state.term}
      </div>
    );
  }
}

ReactDOM.render(<App/> , document.getElementById("app"))
like image 813
Arbnor Lumezi Avatar asked Oct 16 '25 11:10

Arbnor Lumezi


1 Answers

Follow these steps:

  1. Click Settings at the top.
  2. Select the JavaScript tab, and add "Babel" as the JavaScript preprocessor.
  3. In the "quick add" drop-down, select "React" and "ReactDOM".
  4. Paste your React code in the Javascript section.
  5. Add <div id="app"></div> in the HTML section.

Voila!

like image 61
Chris Avatar answered Oct 19 '25 01:10

Chris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!