How to fix the Eslint Preferred-Destroy error?

I would like to shorten the object literal in ES6 as follows:

const loc = this.props.local;

The reason is loc.foo();much easier to enter thanthis.props.local.foo();

But now ESLint complains:

Use object destructuring: prefer-destructuring

I read the error description on eslint.org , but I do not understand this. They have an example that is very similar to my code, but it seems like they look normal?

var foo = object.bar;

How to fix an error without forcing it to be ignored in the file .eslintrc?

+6
source share
3 answers

change your code to:

const local = this.props.local;

to:

const { local } = this.props;

, local.foo() . , .

+13

ES 6, . , : const { local: loc } = this.props

: " loc local this.props".

+1

He tells you to use

const {props: {local: loc}} = this;
0
source

All Articles