Course contentsShow
← React Native
Lesson 21 of 1,5551. The React Native ArchitectureFree lesson

Virtual DOM vs Native Component Trees

You will be able to contrast the reconciliation process of web React with the native view flattening process.

In this lesson, you will learn how the lightweight structure React uses to track state differs from the heavy-duty hierarchy the mobile OS uses to render your app.

The Virtual DOM: The "Blueprint"

In web-based React, you are likely familiar with the Virtual DOM. Think of this as a lightweight, JavaScript-based representation of your UI. When state changes, React compares the new Virtual DOM with the old one (a process called "reconciliation") to calculate the minimum number of changes needed.

Because the browser’s DOM is notoriously slow to manipulate, this "diffing" process acts as a smart filter to keep web performance smooth.

Native Component Trees: The "Physical Structure"

In React Native, we don’t have a browser DOM. Instead, we have Native Component Trees. When your JavaScript code updates, React Native performs its own reconciliation, but instead of updating a browser, it maps your component tree to the host platform’s view system (like UIView on iOS or android.view on Android).

Here is the key difference: while the Virtual DOM is a recursive tree of objects, the Native Component Tree must be "flattened."

View Flattening

To keep your app fast, React Native performs View Flattening. If you have a deeply nested structure of View components that exist purely for layout (like background colors or padding), the Shadow Tree (which we discussed in lesson 16) works to collapse these into a single native view where possible.

Consider this code:

<View style={{ padding: 10 }}>
  <View style={{ backgroundColor: 'blue' }}>
    <Text>Hello World</Text>
  </View>
</View>

In the Virtual DOM, this is three distinct nodes. However, when the UI Manager resolves this to the native platform, it may optimize the tree by flattening those nested View containers into a single native element. This reduces the memory overhead and complexity of the native view hierarchy, a process that doesn't happen in the web's Virtual DOM.

Key Takeaway: While the Virtual DOM is a reconciliation tool for tracking changes, the Native Component Tree is a structural blueprint that React Native flattens to ensure the mobile OS only handles the views that are absolutely necessary for rendering.