Set State with this.setState...help

Set State with this.setState...help
0

#1

Tell us what’s happening:

Can you help me.

Your code so far


class MyComponent extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      name: 'Initial State'
    };
    this.handleClick = this.handleClick.bind(this);
  }
  handleClick() {
    // change code below this line
this.setState({
        compMove: options[compMove],
        playerMove: event.target.id
      }, console.log(this.state.playerMove));
    // change code above this line
  }
  render() {
    return (
      <div>
        <button onClick={this.handleClick}>Click Me</button>
        <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/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react/set-state-with-this-setstate


#2

Use the method

 this.setState({
        //write your code here
});

#3

/
Where to use it

class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
name: ‘Initial State’
};
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
// change code below this line
this.setState({ compMove: options[compMove],
playerMove: event.target.id
}, console.log(this.state.playerMove));
// change code above this line
}
render() {
return (


Click Me

{this.state.name}



);
}
};

This?


#4

Try something like this inside the method I talked about in my last comment

name: "your text here"

#5

@Klaudia Please use 3 backticks on the line before and after any code you post to the forum, so that it formats properly. This has been explained multiple times.

Thank you.


#6

class MyComponent extends React.Component {
constructor(props) {
super(props);
this.setstate({
name: “Initial State”
});
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
// change code below this line
this.setState({
compMove: options[compMove],
playerMove: event.target.id
}, console.log(this.state.playerMove));
// change code above this line
}
render() {
return (


Click Me

{this.state.name}



);
}
};

This is my new code.