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

前端 未结 8 2001
庸人自扰
庸人自扰 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条回答
  • 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  
    );
    
    0 讨论(0)
  • 2020-12-14 08:08

    You will get this error only when your class does not have any life cycle method or constructor. To solve this either you have to disable the lint property or make it as a pure function or create constructor for the class.

    0 讨论(0)
提交回复
热议问题