简体   繁体   中英

How to fix vscode auto spacing issues in react code

Im trying to save some data into a state using object keys in react,

Ex: setText(data[listname][0].feature-type;

But after saving the file it automatically adding a space between featute and type

Ex: setText(data[listname][0].feature - type:

As it is this will resulted as reference error.How to avoid this

As commented, this is the solution if feature-type is a property of the object you are trying to access:

You need to access it as a dictionary setText(data[listname][0]['feature-type'] .

Because there are some limitations to which names can be accessed with a dot (.). And since the property name contains hífen (-), it needs to be accessed as a dictionary. VSCode is formatting different then what you expect because you are giving it invalid syntax.

You can look at this answer: https://stackoverflow.com/a/29888297/8633918 for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM