Extending HTML elements in React and TypeScript while preserving props

后端 未结 6 1103
星月不相逢
星月不相逢 2021-02-04 23:58

I just can\'t wrap my head around this I guess, I\'ve tried probably half a dozen times and always resort to any... Is there a legitimate way to start with an HTML

6条回答
  •  闹比i
    闹比i (楼主)
    2021-02-05 00:18

    I always like to do it this way:

    import React from 'react';
    
    interface ButtonProps extends React.ButtonHTMLAttributes {
      title: string;
      showIcon: boolean;
    }
    
    const Button: React.FC = ({ title, showIcon, ...props }) => {
      return (
        
      );
    };
    

    Then you can do:

提交回复
热议问题