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?
js. While working with React. js components, there are two ways using which you can retrieve/access the component props.
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.
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.
handleSubmit = (event) => { event.preventDefault(); const {onSearch} = this.props const {value} = this.query onSearch(value) event.target.blur(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With