Answer wont let me move on

Tell us what’s happening:
Well I kept getting errors and I checked the solution and its correct, but it will not let me move on to the next lesson because it is saying that the state is not changing the text to You clicked!

  **Your code so far**

class MyComponent extends React.Component {
constructor(props) {
  this.state = {
    text: "Hello"
  // Change code below this line

  // Change code above this line
handleClick() {
    text: "You clicked!"
render() {
  return (
      { /* Change code below this line */ }
      <button onClick = {this.handleClick}>Click Me</button>
      { /* Change code above this line */ }
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0

Challenge: Bind ‘this’ to a Class Method

Link to the challenge:

Right, it isn’t working. When you click the button, the text isn’t getting changed.

The issue that I see is here:

  // Change code below this line

  // Change code above this line

You didn’t do anything there. The instructions were trying to tell you what to do there:

However, the method doesn’t work because it’s using the this keyword that is undefined. Fix it by explicitly binding this to the handleClick() method in the component’s constructor.

When I fix that, the code passes for me.

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