React - Create a Stateful Component

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

class StatefulComponent extends React.Component {
constructor(props) {
  super(props);
  // Only change code below this line
  this.state = {
    name: 'Useful Programmer'
  }
  // Only change code above this line
}
render() {
  return (
    <div>
      <h1>{this.state.name}</h1>
    </div>
  );
}
};

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36

Challenge: React - Create a Stateful Component

Link to the challenge:

You didn’t indicate what problem you are having… but assuming you’re just wondering why your code isn’t passing, check the variable name in your state and see if it matches what they told you to make it.

compiler is showing me error like this ----> The state of

StatefulComponent

should be initialized with a property

firstName

set to a string. The property

firstName

in the state of

StatefulComponent

should render in the

h1

element.

and I worked and edit y code as according to compiler error which it was showing to me but after that it was also not working , can you please try in your directory and help me to find the solution

Well, looking at your code above you did create a state:

this.state = {
    name: 'Useful Programmer'
  }

… and what did you call the property inside that state?

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