React + Typescript: Type of React component with no state/no props

后端 未结 2 1784
盖世英雄少女心
盖世英雄少女心 2021-02-12 18:50

I\'ve seen multiple examples of React components using Typescript:

class Foo extends React.Component {}

It seems there is no a

2条回答
  •  心在旅途
    2021-02-12 19:09

    According to this guideline and my exp, I would say :

    1. class Foo extends React.Component {} when you know you will not recieve props nor state
    2. class Foo extends React.Component {} when you know you will recieve props and state but you really don't care what they look like
    3. class Foo extends React.Component<{}, {}> {} never saw, seems strange
    4. class Foo extends React.Component {} same as null, it's up to you. I see more often null than undefined
    5. class Foo extends React.Component {} bad idea, since seems to be reserved for functions return (when you do not expect one)

    Other opinions are welcomed

提交回复
热议问题