React with TypeScript - define defaultProps in stateless function

前端 未结 7 1545
梦如初夏
梦如初夏 2021-02-01 04:56

I\'m using React with TypeScript and I\'ve created stateless function. I\'ve removed useless code from the example for readability.

interface CenterBoxProps exte         


        
7条回答
  •  一向
    一向 (楼主)
    2021-02-01 05:25

    For Functional Components as of React 16.7.0 the 'React.SFC' type is being deprecated in favour of 'React.FC'.

    Example

    type TFuncComp = React.FC<{ text: string }>
    
    const FuncComp: TFuncComp = props => {props.text}
    
    FuncComp.defaultProps = { text: 'Empty Text' }
    

    Deprecation Warning in Source

    FC (FunctionalComponent) Type in Source

提交回复
热议问题