只是做了简单的封装,欢迎指正
import { Button } from 'antd';import React from 'react';import styles from './MyBtn.less';interface BtnPros { BtnName?: string; onClick?: React.MouseEventHandler<HTMLButtonElement>; children?: any;}export default ({ onClick, children }: BtnPros) => { let BtnName = ''; React.Children.map(children, (child: any) => { if (typeof child === 'string') BtnName = child; }); return ( <> <Button className={styles.btn} onClick={onClick}> {BtnName} </Button> </> );};
.btn { background-color: #f6a04d; color: #fff; &:hover { color: #f6a04d !important; border-color: #f59b4c !important; }}
<MyBtn onClick={clickfun}>click</MyBtn>