0

Recently, Next.js version 10 is released with the newest Image element, which is super helpful for a website with a lot of images!

I get an HTML response from the server something like:

HTML =
"<div>
<p> Some Random text</p>
<img src="something" />
<img src="something" />
<img src="something" />
<img src="something" />
 <div>"

All I want to do is render the HTML into plain text and convert all the img tags to Image during rendering on the page. How can I do this to replace all img to Image?

Zsolt Meszaros
  • 21,961
  • 19
  • 54
  • 57

1 Answers1

0

In your React (JSX/TSX) code change all <img> tags to <Image> tags.

And import it with

`import Image from 'next/image'

Olavi
  • 821
  • 4
  • 12
  • Not sure why this got downvoted, he's right, @Olavi if you explain how to parse html into react elements and replace at the same time I'm sure it's gonna get marked right. Upvoted as whilst too brief your answer didn't deserve a downvote. – Mrk Fldig May 27 '22 at 16:25