I'm using NextJs. I have an html string that is fetched from the server. It represents a blog post and contains several <img> tags. I'm currently rendering the post like this:
const blogpostHtml = "..." // an html string that comes from the server
return (
...
<div
dangerouslySetInnerHTML={{__html: blogpostHtml}}
/>
...
)
And it works fine. However, I'd like to add functionality to the images. I found this library that accomplishes what I want with an uncontrolled component:
...
<Zoom>
<img
alt="some alt"
width="500"
src="the image url"
/>
</Zoom>
...
However, I noticed that I can't simply insert the Zoom tags because it's interpreted as a raw html tag instead of a component. And if I try to render it to a string it loses functionality.
let html = ReactDOMServer.renderToString(
<Zoom>
<img
alt="some alt"
width="500"
src="the image url"
/>
</Zoom>
)
return (
...
<div
dangerouslySetInnerHTML={{__html: html}}
/>
...
)
As you can see in the image, the resulting html is the same as using the Zoom component as intended, but the button loses its event
So how can I combine the html string from the server and the uncontrolled Zoom component to achieve what I want?
