-1

I need to conver incoming string ' ' to img src attribute and pass it as prop to child component. How can I do that?

I tried this, but its not working.

`let blob = new Blob([data.payload], {type: 'image/svg+xml'});

      let url = URL.createObjectURL(blob);
      const image = document.createElement('img');
      image.addEventListener('load', () => URL.revokeObjectURL(url), {once: true});
      image.src = url;`
  • Does one of these help you: https://stackoverflow.com/questions/70309786/how-to-render-svg-and-convert-to-png-in-react-native or https://stackoverflow.com/questions/76232792/converting-svg-to-png-results-in-blank-image – chrwahl May 14 '23 at 09:23

1 Answers1

0

can you please try this code and lemme know if this works or not..

let blob = new Blob([data.payload], {type: 'image/svg+xml'});

let reader = new FileReader();
reader.readAsDataURL(blob);

reader.onloadend = () => {
  const image = new Image();
  image.src = reader.result;

  childComponent.propName = reader.result;
}

If you still facing issue let me know, i will help you ...

Varun Kaklia
  • 366
  • 4
  • 9