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

后端 未结 2 1779
盖世英雄少女心
盖世英雄少女心 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:17

    From https://github.com/DefinitelyTyped/DefinitelyTyped/blob/15b7bac31972fbc081028937dfb1487507ca5fc9/types/react/index.d.ts#L199-L200

    interface Component

    extends ComponentLifecycle { }

    Props and state are initialised to {}, so for a component with no state nor prop we can simply do:

    class Foo extends React.Component {} 
    

提交回复
热议问题