Skip to main content



Consumers of this library can benefit greatly from understanding the basic data flow model to leverage its capabilities. Features such as props will touch on different areas of this data flow.

Hello World!#

Let's start with a simple example:

Minimal working example
import React from 'react';
import { useWindowDimensions } from 'react-native';
import RenderHtml from 'react-native-render-html';
const source = {
html: `
<p style='text-align:center;'>
Hello World!
export default function App() {
const { width } = useWindowDimensions();
return (
This card shows the result of rendering a simple HTML code snippet.
Press on the button below to show how this code renders on your device.

This looks pretty simple. But what exactly is happening under the hood? As laid out in the โ€‹Reinvent the Wheel page, we need some logic to translate the DOM into a structure easily translatable into native elements and support all the features mentioned in the referred page. This data structure is called the Transient Render Tree (โ€‹TRE), see figure below.

Data Flow#

Data Flow Diagram
Document Object Model (DOM)<Element tagName="p" style={{ color: "blue" }}> <TextNode data="Hello World!"/></Element>Transient Render Tree<TBlock tagName="p"> <TPhrasing style={{ color: "blue" }}> <TText data="Hello World!" /> </TPhrasing></TBlock>React Native VDOM<View> <Text style={{ color: "blue" }}> Hello World! </Text></View>HTML Markup<p style="color:blue;"> Hello World!</p>with RenderTTree component fromreact-native-render-htmlC. TTree isrendered intoVDOM.with TRenderEngine.buildTTreemethod from @native-html/transient-render-engineB. TransientRender Tree isassembled.with TRenderEngine.parseDocumentmethod from @native-html/transient-render-engineA. HTML markupis parsedinto DOM.parseDocument()buildTTree()<RenderTTree />
Depiction of data transformations involved in the rendering of an HTML snippet.

We can roughly split the transformations from an HTML string to a React tree in 3 steps:

  1. HTML parsing. In this step, the HTML code is parsed to form a DOM tree. This step is performed by the โ€‹htmlparser2 library.

  2. โ€‹TRT Construction. In this step, the DOM tree is transformed in a TRT. Each node of this tree is referred to as a Transient Node (TNode) which has React-Native compatible styles. This step is performed by โ€‹@native-html/transient-render-engine module.

  3. Transient Render Tree Rendering. In this step, the โ€‹TRT is transformed in a React render tree (VDOM). TNodes are passed to internal and custom renderers.

For more information on โ€‹TRT construction, see โ€‹Transient Render Engine and โ€‹CSS Processing pages.