How to define defaultProps for a stateless react component in typescript?

前端 未结 2 802
小蘑菇
小蘑菇 2020-12-19 07:05

I want to define defaultprops for my pure functional component but I get a type error:

export interface PageProps extends React.HTMLProps

        
2条回答
  •  盖世英雄少女心
    2020-12-19 08:05

    You can type Page like this:

    const Page: StatelessComponent = (props) => (
        // ...
    );
    

    Then you can write Page.defaultProps without needing to cast to any (the type of defaultProps will be PageProps).

提交回复
热议问题