创建采用默认支撑的组件prop的组件

时间:2019-07-13 14:33:26

标签: reactjs

我正在尝试创建一个带有组件属性的按钮组件,默认情况下,我想将此属性指定为<a>标签。这怎么可能?

const StripeConnectButton = ({ component = a }) => {
  const Button = generateButton(component);
  return <Button><span>Connect with Stripe</span></Button>
}

我正在寻找某种直接引用“ a”标签的方式,例如React.DomComponent.a

1 个答案:

答案 0 :(得分:0)

const Anchor = (props) => <a {...props}/>

export const StripeConnectButton = ({ component = Anchor, type = 'blue', subType = 'light' }) => {
  const Button = generateButton(component, type, subType);
  return <Button><span>Connect with Stripe</span></Button>
}