Passing Data to Components

I’m completely incapable of mimicing Mosh in the Passing data to Components episode (E.3 of Composing Components.

Everything exept
state = {
value: this.props.value
}
I get an error that says: Cannot read property ‘value’ of undefined

I’ve checked the value attribute of but there’s nothing wrong.

Did something change in react or something?

It suddenly worked and I have no idea why

Ensure that you have passed the value prop properly

Make the following change in the constructor and it will work

state = {
    value: this.props.value
  };

  constructor(props){
    super(props)
    this.handleIncrement = this.handleIncrement.bind(this);
  }

The solution by @ChaitraNadig works, passing props in two places, (1) as a parameter in the constructor function and (2) as an argument when calling super.

Note that a lot of users might not have this problem because in an earlier lecture, there was an issue with ‘this’ being undefined in a method named ‘handleIncrement’, and Mosh provides two solutions. If you use the solution that involves the bind method in constructor then you’ll get this error described above. If however you use the solution that assigns ‘handleIncrement’ to an arrow function, then the above error doesn’t occur.