Skip to content
Advertisement

Whats the best way to add an SVG to ReactJS

I want to create a component that displays an SVG in React. I am not having any luck, does anyone know a good practice for turns SVG’s into React components.

I tried adding them to <img /> tags and <svg /> tags but i keep getting a broken image icon?

Advertisement

Answer

the best practice that I have found is that save svg in simple SVG tag and import it like this in your project

import { ReactComponent as EmptyWallet } from 'src/assets/svgs/EmptyWallet.svg';

EmptyWallet.svg file will look like this

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement