Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Super expression must either be null or a function, not undefined

I have a problem with react components and props. Here's exception below. What I'm doing wrong?

Uncaught TypeError: Super expression must either be null or a function, not undefined

class Component extends React.component {
  constructor(props) {
    super(props);
    this.state = {
      name: ''
    }
    this.handleChange = this.handleChange.bind(this);
  }

  handleChange(event) {
    this.setState({
      name: event.target.value
    }); 
  }

  render() {
    return (
      <div>
        <input type="text" onChange={this.handleChange} />
        <p>{this.state.name}</p>
      </div>
    )
  }
};

ReactDOM.render(
  <Component />,
  document.getElementById('reactContainer')
)

Codepen link

like image 723
Bybnovskiy Avatar asked Apr 24 '26 12:04

Bybnovskiy


1 Answers

Issue is in this line:

class Component extends React.component {

you used small c in React.component instead of that use C:

class Component extends React.Component {

Check the working code:

class Component extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      name: ''
    }
    this.handleChange = this.handleChange.bind(this);
  }

  handleChange(event) {
    this.setState({
      name: event.target.value
    }); 
  }

  render() {
    return (
      <div>
        <input type="text" onChange={this.handleChange} />
        <p>{this.state.name}</p>
      </div>
    )
  }
};

ReactDOM.render(
  <Component />,
  document.getElementById('reactContainer')
)
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>


<div id='reactContainer'></div>
like image 191
Mayank Shukla Avatar answered Apr 27 '26 01:04

Mayank Shukla



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!