Assuming the following code:
JavaScript
x
2
1
this.props.myFunction();
2
EsLint gives out the following error:
JavaScript
1
2
1
Must use destructuring props assignment react/destructuring-assignment
2
While the current code is clear and concise, if I still wanted to destructure the code and make EsLint happy, how could I do it ?
Advertisement
Answer
The docs for this rule say that properties of props
should be destructured before using them, so just do that:
JavaScript
1
3
1
const { myFunction } = this.props;
2
myFunction();
3