Must use destructuring props assignment (react/destructuring-assignment)

别说谁变了你拦得住时间么 提交于 2021-01-13 08:31:53

问题


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();
}

causes this error:

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

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

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


回答1:


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

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

    event.target.blur();
}


来源:https://stackoverflow.com/questions/53352851/must-use-destructuring-props-assignment-react-destructuring-assignment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!