How to display svg icons(.svg files) in UI using React Component?

前端 未结 7 803
[愿得一人]
[愿得一人] 2020-11-29 22:28

I have seen lot libraries for svg on react but none gave me how to import a .svg in the react component , I have seen code which talk about bring the svg code in to react ra

7条回答
  •  暖寄归人
    2020-11-29 22:53

    If you use create-react-app 2.0 you can now do do it like this:

    import { ReactComponent as YourSvg } from './your-svg.svg';
    

    And then use it just like you would normally use a component:

    const App = () => (
     
    );

提交回复
热议问题