ESLint - Component should be written as a pure function (react prefer/stateless function)

前端 未结 8 2002
庸人自扰
庸人自扰 2020-12-14 07:08

ESLint is giving me this error on a react project.

ESLint - Component should be written as a pure function (react prefer/stateless function)

It poi

8条回答
  •  -上瘾入骨i
    2020-12-14 08:03

    If all you're doing is rendering a jsx template, and not declaring state with constructor(props), then you should write your component as a pure function of props, and not use the class keyword to define it.

    ex.

    export const myComponent = () => (
       // jsx goes here  
    );
    

提交回复
热议问题