Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
¿Cuál es la mejor manera de agregar un SVG a ReactJS?

Quiero crear un componente que muestre un SVG en React. No estoy teniendo suerte, ¿alguien conoce una buena práctica para convertir SVG en componentes React?

Intenté agregarlos a las etiquetas <img /> y <svg /> pero sigo obteniendo un ícono de imagen roto.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

la mejor práctica que he encontrado es guardar svg en una etiqueta SVG simple e importarlo así en su proyecto

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

El archivo EmptyWallet.svg se verá así

 <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 Report

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 Report

0

este es otro que tengo trabajo pero me gusta mucho mas el tuyo gracias 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!