使用组件作为按钮React

时间:2019-03-14 17:08:43

标签: javascript reactjs button svg

我的React应用程序中有按钮,我想使用SVG向其中添加图像,并且发现我需要为我的SVG文件使用单独的组件,因此我遵循了link和使自己成为<SVGIcon />组件。

我尝试将其添加到button中,但似乎不起作用。我通过将onClick添加到<SVGIcon />来尝试将其用作按钮,但是按钮消失了。

如何使用我的SVG组件但保留按钮属性?

<SVGIcon  name="list " width={100}/>
<Button onClick={() => this.playPreviousVideo()} disabled={this.state.activeKey === 1} className="mr-3">
    previous()
</Button>

1 个答案:

答案 0 :(得分:1)

您可能不愿采用的最简单的解决方案是将SVGIcon组件作为Button的子组件呈现。

<Button
  onClick={() => this.playPreviousVideo()}
  disabled={this.state.activeKey === 1}
  className="mr-3"
>
  previous() <SVGIcon name="list" width={100} />
</Button>
相关问题