Why can't I use "this"?


I get the same result when I use"this.state.visibility" and “state.visibility”, why it shows that “this” should not be used inside setState? Thanks!

Please post your actual code instead of a picture. Thanks

What @JeremyLT said, please post actual code: there’s an ask for help button that will create a post for the forum, but failing that just copy the code and pase it here: code is just text, not pictures.

But look:

function example (a) {
  console.log(a)
}

a is an argument to a function, you don’t console.log this.a, you just log a.

class in JS is one way to create an object. You can attach properties and functions (methods) to that object

class Example {
  a = "foo";
  aMethod(a) {
    console.lof(a);
  }
}

The a that is a property not the same as the a that is a parameter for the function

1 Like