When I make a rest call in react, I get a style
and html
response as follows. Is not in String format.
How can I display this in React
as a partial html fragment?
Bear in mind I can’t just use dangerouslySetInnerHTML
.
That will take care of the html yes. But will not recognise the style.
// This won't capture styles.
const Partial = ({ html }) => {
return (
<span
dangerouslySetInnerHTML={{
__html: html.toString(),
}}
/>
);
};
export default Partial;
There are hundreds of styles and hundreds of elements here. The following is just a sample.
Trying to achieve this without any additional libs.
This is the response, not in String format. Believe is text/html.
<style>
.sample {
margin: 0;
}
/* hundreds of other styles */
</style>
<style>
.sample2 {
padding: 0;
}
/* hundreds of other styles */
</style>
<!-- many other style tags -->
<div>
test
<div>another</div>
/* hundreds of other elements */
</div>
<div>
test
<div>another</div>
/* hundreds of other elements */
</div>