Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
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?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

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

<svg>
<path d="M29.73,17.66H0V47.79H29.73V59.28c.21,5,3.88,6.78,8.42,5.25a2.47,2.47,0,0,0,.7-.37c11.47-9,19.37-18,30.84-27l.16-.13c3.49-3.18,2.46-6.8-.93-9.47L40.81,2.61A13.25,13.25,0,0,0,36.65.28C34-.51,31.54.37,30.41,3a10,10,0,0,0-.68,3.93c0,3.57-.05,7.16,0,10.73ZM93.15,64h29.73V94.16H93.15v11.48c-.21,5-3.88,6.79-8.42,5.25a2.24,2.24,0,0,1-.7-.37c-11.47-9-19.37-18-30.84-27L53,83.38c-3.49-3.17-2.46-6.8.93-9.46L82.07,49a13,13,0,0,1,4.16-2.32c2.66-.8,5.11.08,6.24,2.71a10,10,0,0,1,.68,3.94c0,3.56.06,7.16,0,10.72Z" />
</svg>
about 4 years ago · Juan Pablo Isaza Denunciar

0

import React from 'react';
import PropTypes from 'prop-types';

export default function SVG() {
 return (
    <svg
      id="Layer_1"
    >
      <path d="M29.73,17.66H0V47.79H29.73V59.28c.21,5,3.88,6.78,8.42,5.25a2.47,2.47,0,0,0,.7-.37c11.47-9,19.37-18,30.84-27l.16-.13c3.49-3.18,2.46-6.8-.93-9.47L40.81,2.61A13.25,13.25,0,0,0,36.65.28C34-.51,31.54.37,30.41,3a10,10,0,0,0-.68,3.93c0,3.57-.05,7.16,0,10.73ZM93.15,64h29.73V94.16H93.15v11.48c-.21,5-3.88,6.79-8.42,5.25a2.24,2.24,0,0,1-.7-.37c-11.47-9-19.37-18-30.84-27L53,83.38c-3.49-3.17-2.46-6.8.93-9.46L82.07,49a13,13,0,0,1,4.16-2.32c2.66-.8,5.11.08,6.24,2.71a10,10,0,0,1,.68,3.94c0,3.56.06,7.16,0,10.72Z" />
    </svg>
  );
}

SVG.propTypes = {
  value: PropTypes.string,
};
about 4 years ago · Juan Pablo Isaza Denunciar

0

this is another that i got work but I like yours a lot better thank Justin.

 import mySvg from './path/to/image.svg';
 export default function Svg() { 
     return (<img src="/path/to/image.svg" alt="SVG as an image">)
 }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda