Skip to content
Advertisement

Destructuring a function call

Assuming the following code:

this.props.myFunction();

EsLint gives out the following error:

Must use destructuring props assignment  react/destructuring-assignment

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:

const { myFunction } = this.props;
myFunction();
Advertisement