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

141
Views
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 answers
Answer question

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 Report

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