Sign in

this.setState In this case, the value of key is wrapped with []. What is the syntax?

AnirbanDebnath edited in Fri, 16 Sep 2022

What do you mean when you see this grammar on react's official website?


Code source : https :// reactjs . org / docs / form ...

5 Replies
commented on Sat, 17 Sep 2022

That's how it's understood. If the name here does not use the package, does it mean that the key here has been specified, and the name is called name. But if you wrap it with [] it means that name can be a variable.

commented on Sat, 17 Sep 2022


commented on Sat, 17 Sep 2022

Here, the name is wrapped in brackets, which means that the value of the name variable is used as the key

commented on Sat, 17 Sep 2022

[ name ] Is the dynamic creation of object properties, similar to obj [ name ] Like that.

commented on Sat, 17 Sep 2022

Represents a key that evaluates an expression as an object. You can imagine that there is a variable name ='Hello '. If you want to use' hello 'as a key, how do you write it? The following writing has the same effect:

let data = {
  [name]: '123';

let data = {
  hello: '123';