Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 310
Dominik Domanski Avatar asked Nov 17 '18 15:11

Dominik Domanski


People also ask

Should I Destructure props?

js. While working with React. js components, there are two ways using which you can retrieve/access the component props.

What is Destructuring props assignment?

What is Destructuring? Destructuring is a characteristic of JavaScript, It is used to take out sections of data from an array or objects, We can assign them to new own variables created by the developer.

What is Destructuring assignment in React?

The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.


1 Answers

handleSubmit = (event) => {     event.preventDefault();      const {onSearch} = this.props     const {value} = this.query     onSearch(value)      event.target.blur(); } 
like image 55
lomse Avatar answered Sep 23 '22 12:09

lomse