如何通过传递 startIcon 道具在材质 ui 按钮中放置图像

Aak*_*han 2 reactjs material-ui

我正在使用 Material ui 按钮。此按钮应将图像和按钮名称作为其子项。我不想用作我的 Button 的孩子之一,但我想通过将 startIcon 道具传递给 Button 来实现。按钮应如下所示:-

我试过这个:-

<Button className={classes.navButtons} startIcon={ZapierIcon}>
    Zapier
</Button>
Run Code Online (Sandbox Code Playgroud)

但它在按钮中显示了我的图像路径而不是实际图像....任何人都可以提出一些建议我做错了什么。

Sir*_*lam 7

只需通过头像代替图标。

     <Button
        variant="contained"
        color="secondary"
        startIcon={<Avatar src={'http://www.wpsimplesponsorships.com/wp-content/uploads/2019/05/cropped-icon-256x256.png'} />}
      >
        Delete
      </Button>
Run Code Online (Sandbox Code Playgroud)

https://codesandbox.io/s/bold-dew-3rl6z