问题
Beginner question struggling with React Component implementation. I have tried everything in the cookbook on this error but no luck.
Expected 'this' to be used by class method 'aaaa'
What is wrong with his code:
import React from 'react';
class TestStuff extends React.Component {
constructor(props) {
super(props);
this.aaaa = this.aaaa.bind(this);
}
aaaa() {
console.log('dddddd');
}
render() {
return <div>test</div>;
}
}
export default TestStuff;
回答1:
The warning is just saying, I see that you have this method in this class but it's not using any properties in the class. So either make it a static
method or access a class property inside the method.
https://eslint.org/docs/rules/class-methods-use-this
来源:https://stackoverflow.com/questions/65311579/beginner-question-struggling-with-react-component-implementation-getting-strange