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

144
Vistas
Displaying raw SVG in React

Hi there I'm getting an SVG from an api in this form:

<svg> ..... </svg>

I'm passing this svg as an props to this MainDisplay Component

class MainDispay extends React.Component {
  constructor(props) {
    donothing(props);
    super(props);
    console.log("props", this.props.Collections);
  }

  async componentDidMount() {}

  render() {
    return (
      <>
        {this.props.Collections.map((DataObj, i) => (
          <div key={i}>
            <div>{DataObj.name}</div>
            {this.props.Collections[i].DisplayProps.map((Data, j) => (
              <div key={j}>{Data.image_data}</div>
            ))}
          </div>
        ))}
      </>
    );
  }
}

Only problem is that the Data.image_data displays <svg>.....<svg> instead of an image.

Any idea how to display image instead. THANKS in ADVANCE

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

0

You can use Reacts dangerouslySetInnerHTML to render any supplied html string:

<div key={j} dangerouslySetInnerHTML={{__html: Data.image_data}} />

Be careful! This attribute opens your app for vulnerable cross-site scripting attacks. Make sure to sanitize your image_data to strip any html other than svg. More on this e.g. in this answer: https://stackoverflow.com/a/1637573/9969672

about 4 years ago · Juan Pablo Isaza Denunciar

0

One effective way is to pass SVG as a source of 'img' tag.

<img key={j} src={Data.image_data} />
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