Skip to content
Tutorials Center
My learning

Topics

Lesson 99 of 132 ยท Ecosystem

React Native, Expo and Beyond the Browser

See how React runs outside the browser - React Native and Expo, shared logic, Electron and Tauri, email, PDF and terminal renderers - and build a toy renderer to see how it works.

Everything you have built so far ends up as HTML elements in a browser. But React itself knows nothing about HTML. It describes a tree of components and works out what changed; a separate piece of code, the renderer, turns those changes into something real. The browser renderer is react-dom. Swap it for another one and the same ideas (components, props, state, hooks, effects) drive a phone app, a command-line tool, a PDF or an email.

This lesson explains that split, then tours the most important non-browser targets: React Native and Expo for mobile, Electron and Tauri for desktop, and renderers for terminals, PDFs and email. You met the render and commit phases in how React works; here they become the reason React travels so well. We finish by writing a toy renderer so that nothing about the idea stays magical.

React core versus renderers

Two packages do the work:

  • react holds components, hooks, context, memo, Suspense and the element-creation function. It has no idea what a "screen" is.
  • A renderer (react-dom, react-native, ink, @react-pdf/renderer, ...) provides the host components (the built-in building blocks: div and input on the web, View and Text on mobile) and the code that creates and updates the real thing.

During a render React produces a tree of elements, compares it with the previous tree, and hands the renderer a short list of operations: create this node, set this property, move that child, remove this one. The renderer applies them. This is why reconciliation and hooks behave identically in a browser and on a phone.

A host component is a built-in element type the renderer understands. In react-dom that is every HTML and SVG tag. In React Native it is View, Text, Image and friends. Your own components are always made of other components, and the bottom of the tree is always host components.

React Native

React Native renders to the platform's own native views. A <View> becomes a UIView on iOS and an android.view.View on Android; a <Text> becomes a native text label. It is not a web page in disguise, so there is no HTML, no CSS cascade and no DOM.

A screen looks very familiar:

JSX
// Read-only: React Native code, needs the react-native package and a device or simulator.
import { useState } from 'react';
import { View, Text, Pressable, StyleSheet } from 'react-native';

export default function Counter() {
  const [count, setCount] = useState(0);

  return (
    <View style={styles.container}>
      <Text style={styles.title}>Count: {count}</Text>
      <Pressable style={styles.button} onPress={() => setCount(count + 1)}>
        <Text style={styles.buttonText}>Add one</Text>
      </Pressable>
    </View>
  );
}

const styles = StyleSheet.create({
  container: { flex: 1, alignItems: 'center', justifyContent: 'center' },
  title: { fontSize: 24 },
  button: { marginTop: 12, padding: 12, backgroundColor: '#4f46e5', borderRadius: 8 },
  buttonText: { color: 'white' },
});

The state logic is exactly what you already know. What differs:

Web (react-dom) React Native
div, span, p, button View, Text, Pressable
onClick onPress
Any text inside any element Text must be inside <Text>
CSS files and selectors StyleSheet objects, Flexbox only, no cascade, no selectors
<img src> <Image source>
<input> <TextInput>
URLs and links A navigation library (React Navigation, Expo Router)
Scrolling by default Explicit ScrollView or FlatList (virtualized)

Styles use camel-case property names and numbers instead of units. Layout is Flexbox with the column direction by default, which is the opposite of CSS's default row.

Expo

Expo is a framework and toolchain around React Native. Without it you configure Xcode, Android Studio and native build tools yourself. With it you can start a project with one command, run it on your own phone by scanning a QR code, use a large library of ready-made native modules (camera, location, notifications, file system), navigate with file-based routing (Expo Router), and build and submit store binaries in the cloud (EAS). For most new React Native apps, Expo is the recommended starting point. These are terminal sessions, shown read-only:

Terminal
# Read-only: run these in a terminal on your own machine.
npx create-expo-app@latest my-app
cd my-app
npx expo start

When you outgrow Expo's modules you can still add custom native code, so choosing Expo is not a dead end.

Sharing code between web and mobile

A common goal is "write once, run everywhere". The honest answer is: share logic, not markup.

  • Easy to share: reducers, custom hooks that do not touch the DOM, validation schemas, API clients, formatting helpers, types, constants.
  • Hard to share: screens and layout, because div and View are different host components, and navigation, gestures and platform conventions differ.

Tools such as React Native Web and Expo's web support can render View and Text in a browser, and design-system projects build one component API on top of both. That can work well, but expect to maintain platform-specific files for the awkward parts.

The runnable demo below shows the practical pattern. The state logic is a plain reducer written once; two completely different "views" use it, one rendering web elements and one rendering text lines the way a terminal would:

One reducer, two views

Each view owns its own counter instance, because each calls useCounter() itself. Nothing in counterReducer or useCounter cares which one is calling. In a real monorepo the shared pieces would be a package imported by both the web app and the mobile app, and only the two view components would differ.

Another technique is to write a component against abstract primitives and let the platform decide what they are. Design systems for web and mobile do this: the screen imports Stack and Label from a package, and each platform ships its own implementation. Context can model the idea in one file:

Components that do not know their host

Both buttons run the same LikeButton, with the same hook and the same logic. Only the objects supplied through context differ. React Native Web uses a bigger version of this same idea: it implements View and Text with div and span.

Desktop: Electron and Tauri

You do not need a special React renderer for desktop apps. Both Electron and Tauri show a web page in a window and add APIs to reach the operating system (files, menus, notifications, auto-update). Your React app is an ordinary react-dom app.

Electron Tauri
Web engine Bundles Chromium Uses the system web view
Backend language Node.js Rust
App size Large (tens to 100+ MB) Small (a few MB)
Consistency Same engine everywhere Engine varies per OS

VS Code, Slack and Discord are Electron apps. The trade-off is simple: Electron gives the most predictable rendering and an enormous ecosystem at the cost of size and memory; Tauri is lean but asks you to be comfortable with Rust for native features.

TEXT
my-desktop-app/
  src/            <- your React app, unchanged
  electron/       <- main process (Node.js): creates the window, talks to the OS
  package.json

Other renderers

Because a renderer only needs to create, update and remove nodes, anything that looks like a tree can be a target.

Terminals with Ink

Ink renders React components as terminal output. Box (Flexbox layout) and Text are its host components, useInput reads key presses, and state updates re-draw the screen. Many command-line tools use it for interactive menus and progress displays:

JSX
// Read-only: needs the npm packages ink and react, run with Node in a real terminal.
import { render, Box, Text, useInput } from 'ink';
import { useState } from 'react';

function App() {
  const [count, setCount] = useState(0);
  useInput((input) => {
    if (input === ' ') setCount((c) => c + 1);
  });
  return (
    <Box borderStyle="round" padding={1}>
      <Text color="green">Presses: {count} (press space)</Text>
    </Box>
  );
}

render(<App />);

PDF and email

  • @react-pdf/renderer lets you describe a PDF with Document, Page, View and Text components, using Flexbox-style layout, and produces a real PDF file.
  • React Email builds HTML emails from components. Email clients support only a narrow, old subset of HTML and CSS, so the library supplies safe building blocks and renders them to a string.

The email case needs no special renderer at all: react-dom/server can turn a component tree into an HTML string, and that works in the browser build too, so you can try it here:

Rendering an email to an HTML string

renderToStaticMarkup produces plain HTML with none of the extra attributes React adds for hydration, which is what you want for an email. A mail service sends the string. The same trick generates invoices, static pages and Open Graph images.

Other targets

The list keeps growing: React Three Fiber renders components as 3D objects in Three.js scenes, React Konva and React PixiJS draw on canvases, and there are renderers for game UIs, smart TVs and VR. Each one provides its own host components, and your knowledge of hooks and state carries straight over.

Writing a toy renderer

The real reconciler used by react-dom and React Native is a large piece of engineering, and its public API (react-reconciler) is unstable and not installed in our editor. We can still see the idea in a few lines, with one big simplification: this renderer re-renders the whole tree from scratch and has no state.

Remember that JSX produces plain objects with a type and props. A function component is just a function that returns more elements. A renderer walks the tree: if the type is a function, call it and keep going; if it is a string, that is a host component, so create a node for it. Here the "nodes" are lines of text for a pretend terminal.

A toy renderer for a text screen

The first block prints {"type":"TodoList","props":["tasks"]} and the second prints a title line, a bullet for each task, and done under the finished one. Notice what the toy renderer lacks, because that is the real reconciler's job: it cannot run hooks (calling useState outside React throws an error), it redraws everything every time instead of diffing against the previous tree, and it has no scheduling, no keys-based matching and no effects. A real renderer implements a small set of functions (create an instance, append a child, commit an update, remove a child) and lets React's core do everything else. That small interface is what makes new renderers possible.

Choosing a target

  • Building a website or a web app: react-dom, usually inside a framework.
  • Building iOS and Android apps with one team that knows React: React Native with Expo.
  • Packaging a web app as a desktop program: Electron (predictable, heavier) or Tauri (small, Rust).
  • Generating documents or messages from data: react-dom/server, React Email or @react-pdf/renderer.
  • Building a CLI with interactive UI: Ink.

Before investing in a non-browser target, check what is different (host components, styling, navigation, testing tools). The React you have learned transfers fully; the platform around it does not.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What does a React renderer do?

    React core computes what changed; the renderer (react-dom, react-native, ink, ...) creates, updates and removes the real nodes.
  2. 2. Which code is the easiest to share between a React web app and a React Native app?

    Logic does not depend on the host components. Markup, styling and navigation differ between platforms, so those are the hard parts to share.
  3. 3. In React Native, where must text be placed?

    React Native has no implicit text nodes in views. Strings must be rendered inside a Text component.
  4. 4. What is the main difference between Electron and Tauri?

    Both display a normal web page in a window. Electron ships its own browser engine, so apps are larger; Tauri reuses the operating system's web view, so apps are small.
  5. 5. Why can't our simple toy renderer run components that call useState?

    Hooks store state in React's own bookkeeping for the component instance. Calling a component function outside React gives hooks nothing to attach to.

Summary

  • React core describes UI and decides what changed; a renderer owns the host components and applies the changes to a real target.
  • React Native renders native views (View, Text, Pressable) with Flexbox StyleSheet styles; Expo is the recommended toolchain for starting out.
  • Share logic (reducers, hooks, schemas, API code) between web and mobile; expect to write platform-specific screens and navigation.
  • Electron and Tauri wrap an ordinary react-dom app in a desktop window; Ink, React PDF and React Email render to terminals, documents and email.
  • renderToStaticMarkup turns a component tree into an HTML string, which works for emails and invoices.
  • A toy renderer shows the principle: walk the element tree, call function components, create nodes for host types. Real reconcilers add hooks, diffing and scheduling.

Next: Project: Todo App