必须使用破坏性道具分配(反应/破坏性分配) [英] Must use destructuring props assignment (react/destructuring-assignment)

查看:194
本文介绍了必须使用破坏性道具分配(反应/破坏性分配)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将eslint airbnb标准应用于我的代码,所以现在此代码:

I've applied eslint airbnb standard to my code, so now this code:

handleSubmit = (event) => {
  event.preventDefault();
  this.props.onSearch(this.query.value);
  event.target.blur();
}

导致此错误:

[eslint]必须使用破坏性道具分配(反应/破坏性分配)

[eslint] Must use destructuring props assignment (react/destructuring-assignment)

onSearch 基本上是一个将值传递给父组件的触发器.

onSearch basically a trigger that passes up a value to parent component.

如何重构此代码以满足eslint要求?

How do I refactor this code to meet the eslint requirements?

推荐答案

handleSubmit = (event) => {
    event.preventDefault();

    const {onSearch} = this.props
    const {value} = this.query
    onSearch(value)

    event.target.blur();
}

这篇关于必须使用破坏性道具分配(反应/破坏性分配)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆