React: Feature request: adding dangerouslySetOuterHTML (or HTML-comment component)

Created on 27 Sep 2019  路  3Comments  路  Source: facebook/react

Currently there is only the option to have dangerouslySetInnerHTML, but there is no way to create a raw HTML output (like a HTML comment).

For the background where I'm heading to with my feature-request:
I am tinkering with ReactJS (latest version __16.9.0__) as some kind of static website generator where ReactJS should be used as the "templating engine". As I do not want to run a nodejs-server, or React at all on the resulting website, __SSR is no option__ for me (and please don't advocate me to use SSR).

As I am using renderToStaticMarkup of the react-dom/server, I can not use the existing ways like manipulating the "DOM"-node, because componentDidMount and useEffect do not work here.

For reference, I tried these tricks without luck (please ignore the asked question on SO, I only talk about the code of the given answers):

This topic was asked in some different ways, but not in combination with outerHTML. I think these issues might be related to this:

A way to return raw HTML from an unmounted component?
https://github.com/facebook/react/issues/7374

What does dangerouslySetInnerHTML prop do? How is it achieved?
https://github.com/facebook/react/issues/14509

What is the current behavior?

There is no way.

What is the expected behavior?

If possible, I would like to have a way without having to deal with any "workaround"-construct

<React.RawText text={"<!-- some HTML comment -->"} />

If possible, I would like to have a way without having to deal with a <div />

<React.Fragment rawUnsafeHTML={{__html: "<!-- some HTML comment -->"}} />

Otherwise by using a div as some kind of "transport-object"

<div dangerouslySetOuterHTML={{__html: "<!-- some HTML comment -->"}} />

All 3 comments

I think this issue should be an RFC:
https://github.com/reactjs/rfcs

I think #12014 should probably be rolled into the same RFC. The RFC process encourages thoroughly exploring a proposed API change, considering alternative proposals, etc.

I'm going to close this issue (in this repo) and suggest you create an RFC following the process outlined here.

Was this page helpful?
0 / 5 - 0 ratings