react icon indicating copy to clipboard operation
react copied to clipboard

A way to return raw HTML from an unmounted component?

Open BlockChange opened this issue 10 years ago • 1 comments

I've asked the same question here but it seems that the only way is to use ReactDOMServer.renderToStaticMarkup(component) which must be a mounted component first, and I'd just like to feed raw HTML to a plugin like the above linked question.

I also like to avoid jQuery with this, and just have a way to mount a component in the shadow, and then have the raw HTML ( not sure how it's called, when you console.log a html element, in chrome it outputs the html as a sort of native html object )

The only other way I can imagine is using a ref to an element, but that still has to be mounted.

BlockChange avatar Jul 29 '16 11:07 BlockChange

Server-side components are never mounted (and componentDidMount doesn't fire on the server). ReactDOMServer.renderToStaticMarkup will literally just generate HTML markup to use.

See this fiddle: https://jsfiddle.net/onq7ooyj/1/

apapirovski avatar Aug 05 '16 15:08 apapirovski