How to use an SVG file in a SvgIcon in Material-UI

后端 未结 3 1149
心在旅途
心在旅途 2021-02-11 13:06

I\'ve got an SVG file and I want to make an SvgIcon component out of it, how should I do that?

In the documentation, all the examples use either predefined Material Icon

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-11 13:54

    You can import SVGs directly as React components and use them in :

    import React from "react";
    import { ReactComponent as Logo } from "./logo.svg";
    import SvgIcon from "@material-ui/core/SvgIcon";
    
    const App = () => (
      
        
      
    );
    
    export default App;
    

    See also: https://create-react-app.dev/docs/adding-images-fonts-and-files/#adding-svgs

    Unfortunately React seems not able to render all kind of SVGs (e.g. modified with Inkscape, Illustrator) yet. But at least the default logo.svg inside a create-react-app project works.

提交回复
热议问题