Skip to content
Advertisement

React.js: Raw HTML string does not gets recognized as HTML elements from Node.js

I am sending a raw HTML from node.js to react. and It was successful. However, when I try to render it, they are render as raw string as opposed to HTML elements

This is how I get the string from front-end:

JavaScript

The render method from my react(Simplified) looks like this:

JavaScript

In my server.js, i have the following code handeling the post request:

JavaScript

Why doesn’t react render the string as an HTML elements, but rather a raw string?

Advertisement

Answer

You may be able to leverage dangerouslySetInnerHtml, like so:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement