React Curriculum - Create a Stateful Component

I am working towards the FrontEnd libraries React topics - I have tried several attempts correct this code and I am still unable to find a solution, every attempt to change name to firstName, FirstName, Name , name, Nanji, is failing, please can someone assist, have already googled also, but cannot find correct way / solution to this:
I have tried line 12, with this.state.firstName, and FirstName, still not passing the test:, the 2 errors I get are:-

  • Failed:The state of StatefulComponent should be initialized with a property firstName set to a string.

  • Failed:The property firstName in the state of StatefulComponent should render in the h1 element.

1 class StatefulComponent extends React.Component {
2   constructor(props) {
3    super(props);
4    // initialize state here
5    this.state = {
6     name: "Nanji"
7  }
8 }
9  render() {
10    return (
11     <div>
12        <h1>{this.state.name}</h1>
13     </div>
14   );
15 }
16 };

class StatefulComponent extends React.Component {
  constructor(props) {
    super(props);
    // initialize state here
    this.state = {
      name: "Nanji"
    }
  }
  render() {
    return (
      <div>
        <h1>{this.state.name}</h1>
      </div>
    );
  }
};

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Hello , many thanks, I have resolved this and found the answer, line 6 needs to have firstName: instead of name:

Many thanks.

Congratulations on figuring it out! Happy coding.

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