How to fix Eslint error “prefer-destructuring”?

前端 未结 3 1559
悲&欢浪女
悲&欢浪女 2020-12-08 18:57

I wanted to shorten an object literal in ES6 like this:

const loc = this.props.local;

The reason is loc.foo(); is a lot easier

3条回答
  •  长情又很酷
    2020-12-08 19:14

    change your code from:

    const local = this.props.local;
    

    to:

    const { local } = this.props;
    

    They are equivalent and you can call local.foo() in the same way. except that the second use object destructuring.

提交回复
热议问题