Beginner question struggling with React Component implementation getting strange “this” error

╄→尐↘猪︶ㄣ 提交于 2021-01-05 07:26:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!