I'm using react-native-render-html to render html.
The renderers
method allows me to provide custom function to render a particular tag. However I want to replace the children with my custom component, using the raw inner HTML from the source.
Consider. I have the below html snippet provided to <HTML />
component:
<a> <b> <c meta="xyz"> Some text </c> <b> </a>
and I have a custom renderer which returns a component that takes a html string and does some magic with it:
const renderers = {
c: () => (
<Custom html={/** how do I get "<c meta="xyz"> Some text </c>"? */} />
)
}
The API was not initially designed to handle these kind of use cases, but as for version 5.0.0, it is very easy!
Version 6.x
Version 5.x
Since version 5, it is extremely easy with the help of the new
domNodeToHTMLString
util, see snippet below:Version 4.x and below
To use this hack, you'll need to add “stringify-entities” to your list of dependencies. What this hack does basically, is to use the
alterNode
hook to add a very unconventional__rawHtml
attribute to the DOM node. The attribute will be thereafter passed to the renderer function.