React with TypeScript - define defaultProps in stateless function

前端 未结 7 1542
梦如初夏
梦如初夏 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:27

    Simplest for me is to define (partial) defaults in the defaultProps directly:

    export default class TSError extends React.Component<ITSErrorProps, {}> {
      private static defaultProps: Partial<ITSErrorProps> = {
        fullPage: true,
        controlClick: true,
        doubleClick: true
      };
    
    ...
    
    }
    
    0 讨论(0)
提交回复
热议问题