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

89
Vistas
React component to render SVGs dynamically from props

I have a component, lets call it Frame and I want it to dynamically render svgs into the body of the parent component.

I have a prop which is props.svg which is a link to the location of where the svg is stored. eg. ./files/svg/Hello.svg

//parent component
<Frame src={props.svg} />

//child component
const Frame = (src) => {
  return (
    <>
      {src}
    </>
  )
}

However it's not rendering the svg as I intended. How should I be storing the SVG as it's native file or some other way? and how would I get it from the file instead of printing the file location ./files/svg/Hello.svg?

EDIT: I understand how to import an SVG file, but my issue is that the props from the parent component will change dynamically so I'm unsure how to import it correctly as the prop (src) of the SVG will change. I also don't want to build a component for each SVG if it's avoidable.

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

0

You have to transform your SVG file to a component, just like this (create a file.js) :

const File= () => (
//put the content of SVG
    <svg
        xmlns="http://www.w3.org/2000/svg"
    >
    </svg>
)
export default File

and then use :

<Frame src={ <File />} /> 
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