Render State in the User Interface Another Way

Render State in the User Interface Another Way
0.0 0

#1

Tell us what’s happening:

Your code so far


class MyComponent extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      name: 'freeCodeCamp'
    }
    const name = this.state.name;
  }
  render() {
    // change code below this line

    // change code above this line
    return (
      <div>
        { /* change code below this line */ }
        <h1>{ name }</h1>
        { /* change code above this line */ }
      </div>
    );
  }
};

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.1 Safari/605.1.15.

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react/render-state-in-the-user-interface-another-way


#2

Please tell us exactly what you need help with. Be as detailed as you can.


#3

Hi, I’m not sure what I’m missing in this challenge. <MyComponent /> should render the name in H1 element, but it doesn’t.

Any Idea?


#4

You need to think about where you should be initializing your const name.


#5

Oops! Thanks. It’s worked.