React: Create a Stateful Component

The last updated answer was Aug 2020, so I wanted to update the answer. I’m pretty proud that I figured it out. So, the only solution given is:

this.state = {
name : “Name”
}

This answer is accurate but also only half the answer, the other half is supposed to have you input your name into the code.
Example: ( this was my answer)

this.state = {
firstName: “Bambu”
}

So your answer should look like this:

//
this. state = {
name: “firstName”
}

this.state = {
firstName: “Bambu”
}
//

First of all, keep in mind that the hints are not maintained. (Personally I wish we’d get rid of them.)

Next, this hint was obviously written based on an earlier version of this challenge, when the property was named “name” - that is what it is in the constructor and the JSX.

Lastly, this:

this. state = {
  name: “firstName”
}

this.state = {
  firstName: “Bambu”
}

won’t do what you think it will. You are overwriting this.state with an object literal so that after these lines, this.state won’t have a “name” property. The:

this.state = {
  firstName: "Bambu"
}

would be the right answer.

But again, the hints aren’t really maintained. I don’t even know if there is a path to fix it.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.