Query returning html elements. How to append?
My api endpoint returns a html <ul><li></li>Ï</ul> element. How can I append that from the query data to my react component?
2 Replies
wise-white•3y ago
Assuming the html is returned as a string from your api, you would probably need to use something like
dangerouslySetInnerHTML to get React to render it: https://beta.reactjs.org/reference/react-dom/components/common#dangerously-setting-the-inner-html
As mentioned in the docs:
This is dangerous. As with the underlying DOM innerHTML property, you must exercise extreme caution! Unless the markup is coming from a completely trusted source, it is trivial to introduce an XSS vulnerability this way.
Common components (e.g. )
A JavaScript library for building user interfaces
absent-sapphire•3y ago
You want to be very careful doing this (hence the "dangerously" prefix). Is this a backend you own? If so, you might be better off returning JSON data and rendering elements from that on the client