Fetch Once, Render Everywhere: React Server Components in Expo Router

Rate this content
Bookmark
React Native has become a powerful way to build client-side applications. ExpoRouter, a file-based routing mechanism, allows developers to build React apps that run on web and native platforms using the same codebase. It supports nested routing and uses familiar web APIs like link and href. ExpoRouter is introducing React Server Components, enabling server-driven UI for all platforms. This approach allows server-side rendering and streaming server-rendered content, making it easier to build high-powered AI native apps. It supports features like dynamic movie cards, smooth scrolling, and optimized network requests. ExpoRouter complies with app store policies by not sending any native code dynamically and supports iOS, Android, and web platforms. The developer experience is improved by simplifying server-driven UIs and reducing the need for client-side data fetching.

From Author:

We’ve been hard at work to create a first-look at data fetching, server rendering, and streaming in universal Expo Router apps.

This talk has been presented at React Summit 2024, check out the latest edition of this React Conference.

FAQ

React Native is a framework for building native applications using JavaScript and React. It allows developers to create apps that run on both iOS and Android platforms using the same codebase.

Evan Bacon is an engineer and the creator of ExpoRouter, a file-based routing mechanism for building React apps that run on both web and native platforms from the same codebase.

ExpoRouter is a file-based routing mechanism for building React apps that run on both web and native platforms from the same codebase. It uses familiar web APIs like link and href and supports nested routing for organizing routes.

React Server Components are a cutting-edge approach to server rendering, allowing for the seamless integration of server and client code. They enable dynamic, server-driven UIs and reduce the need for client-side data fetching.

ExpoRouter simplifies the integration of AI by enabling server-driven UI and streaming server-rendered content. This makes it easier to build high-powered AI native apps that can interact with server-side logic in real-time.

Server-driven UI enables dynamic rendering based on various criteria such as user type, location, and more. It allows for A/B testing and high variation in UI, leading to better performance and user experience.

The source code for ExpoRouter is being actively developed and merged into the Expo repo. Developers can follow the progress on GitHub and will be able to access it once it is officially released.

ExpoRouter complies with app store policies by not sending any native code dynamically. It adheres to guidelines that prevent changing the approved content and behavior of an app, ensuring that all features are pre-approved.

ExpoRouter supports iOS, Android, web, and other platforms through its universal file-based routing system. It provides a seamless experience across different devices and operating systems.

ExpoRouter improves developer experience by simplifying the creation of server-driven UIs, reducing the need for client-side data fetching, and enabling rapid development with a unified codebase for web and native apps.

Evan Bacon
Evan Bacon
28 min
14 Jun, 2024

Comments

Sign in or register to post your comment.

Video Transcription

1. Overview of React Native and exporouter

Short description:

React Native has grown to become the most impactful way to build client-side applications. I'm Evan Bacon, an engineer and the creator of exporouter. It's the first file-based routing mechanism for building React apps that run on both web and native platforms from the same code base. It uses familiar web APIs like link and href to move between routes, and it's also a nested routing system. Expo provides universal solutions to most aspects of app development. Data fetching and server rendering bring interesting opportunities.

When React Native was first announced nearly 10 years ago, it had a very simple premise, which was web the good parts. From this basic concept, React Native has grown to become the most impactful way to build client-side applications. If you fast-forward to now, React Native powers hundreds of the most-used apps in the app store trending list every single day. Really no signs of slowing down. So where do we go from here?

I'm Evan Bacon, an engineer and the creator of exporouter. It's the first file-based routing mechanism for building React apps that run on both web and native platforms from the same code base. It feels like magic. By simply creating files in the app directory, exporouter instantly creates robust navigation for both your native app and your website. It uses familiar web APIs like link and href to move between routes, and it's also a nested routing system, enabling you to organize routes into folders to establish shared UI like tab bars, headers, drawers, so on and so forth. And it's also a... It also has day-one support for the new React compiler, thanks to our collaboration with the meta team. This means you no longer need to write use memo or use callback in your apps, leading to a much better experience for both users and developers. We'll be installing compiler by default in the next version of Expo CLI, so you can flip it on and off. It's actually pretty sweet, because you can turn it off without having to restart the dev server. Really slick. There are many aspects to app development, and Expo provides universal solutions to most of them. But all of these solutions are primarily targeted at building client-side applications. And there's only so much that you can do with the client on its own. Things get really interesting when you bring in data fetching and server rendering.

2. Server-Driven UI and React Server Components

Short description:

Most native apps operate like single-page websites, resulting in slower performance and limited networking. Popular apps utilize server-driven UI for A-B testing and dynamic rendering. However, indie developers often face challenges due to the lack of accessible frameworks. ExpoRouter aims to address this by introducing React server components, enabling powerful server-driven UI for all platforms. The progress in implementing React server components is exciting, showcasing the potential of modern rendering techniques. With ExpoRouter, building high-powered AI native apps becomes easier, utilizing streaming and server rendering capabilities.

From a data perspective, most native apps operate essentially like single-page websites. Which is old now data. This means slower performance and substantially less networking. Popular native apps such as Lyft and Netflix, Reddit, and many others use some form of server-driven UI in their applications. But it's very complicated to configure, and as a result, it's out of reach for most app developers.

They do this so they can A-B test functionality and render UI with a high degree of variation based on all sorts of criteria, such as user type, location, the currency you use, the temperature in your region, lots of different things. The approaches vary in many small ways, but they do share some common architecture, such as using JSON as a static UI representation. Think of this JSON as HTML, but for custom native runtimes. And we can see a pattern here from the amount of apps that use all these very similar systems. And that is that server-driven UI is an important system for building apps, but it's just not very accessible to indie developers. All these groups have these frameworks. They are not open source.

So it got me to thinking. What if we could make server-driven UI available to everyone? But also the most powerful version of it ever imagined. And that is the goal of ExpoRouter. Now, to do this, we're bringing React server components, the most cutting-edge approach to server rendering to all platforms, iOS, Android Web, and anything else, through ExpoRouter. This is a huge undertaking. This will require refinement in many different libraries across the universal ecosystem. Our official implementation of React server components for universal apps is currently in early development. But it's worth sharing, because the progress is really exciting. And frankly, it's pretty inspiring to see what apps are capable of when they use modern rendering techniques from the web.

Now, there's a lot to RSE, such as server actions, concurrent routing, flights, et cetera. But I figured it would be easier to just show you guys a demo of what's possible. So I've been really interested in AI, as has everyone. But it's historically been very hard to build high-powered AI native apps. And this is because streaming and server rendering are both critical aspects of working with an LLM. But with React server components and ExpoRouter, it's actually really, really easy to work with AI. So here I have a chat GPT-like app which pings OpenAI with a React server action and streams in native text from the server. So think of this as a chat GPT-style app, right? Everything that returns back from the server is server rendered, though. Or at least partially server rendered, because we also have client components.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Simplifying Server Components
React Advanced Conference 2023React Advanced Conference 2023
27 min
Simplifying Server Components
Top Content
Watch video: Simplifying Server Components
React server components simplify server-side rendering and provide a mental model of components as pure functions. Using React as a library for server components allows for building a basic RSC server and connecting it to an SSR server. RSC responses are serialized virtual DOM that offload code from the client and handle interactivity. The client manifest maps serialized placeholders to real components on the client, enabling dynamic rendering. Server components combine the best of classic web development and progressive enhancement, offering the advantage of moving logic from the client to the server.
Exploring React Server Component Fundamentals
React Day Berlin 2023React Day Berlin 2023
21 min
Exploring React Server Component Fundamentals
Top Content
Watch video: Exploring React Server Component Fundamentals
This Talk introduces React Server Components (RSC) and explores their serialization process. It compares RSC to traditional server-side rendering (SSR) and explains how RSC handles promises and integrates client components. The Talk also discusses the RSC manifest and deserialization process. The speaker then introduces the Waku framework, which supports bundling, server, routing, and SSR. The future plans for Waku include integration with client state management libraries.
And Now You Understand React Server Components
React Summit 2024React Summit 2024
27 min
And Now You Understand React Server Components
Top Content
In this Talk, Kent C. Dodds introduces React Server Components (RSCs) and demonstrates how to build them from scratch. He explains the process of integrating RSCs with the UI, switching to RSC and streaming for improved performance, and the benefits of using RSCs with async components. Dodds also discusses enhancements with streaming and server context, client support and loaders, server component rendering and module resolution, handling UI updates and rendering, handling back buttons and caching, and concludes with further resources for diving deeper into the topic.
A Practical Guide for Migrating to Server Components
React Advanced Conference 2023React Advanced Conference 2023
28 min
A Practical Guide for Migrating to Server Components
Top Content
Watch video: A Practical Guide for Migrating to Server Components
React query version five is live and we'll be discussing the migration process to server components using Next.js and React Query. The process involves planning, preparing, and setting up server components, migrating pages, adding layouts, and moving components to the server. We'll also explore the benefits of server components such as reducing JavaScript shipping, enabling powerful caching, and leveraging the features of the app router. Additionally, we'll cover topics like handling authentication, rendering in server components, and the impact on server load and costs.
Server Components: The Epic Tale of Rendering UX
React Summit 2023React Summit 2023
26 min
Server Components: The Epic Tale of Rendering UX
Top Content
Watch video: Server Components: The Epic Tale of Rendering UX
This Talk introduces server components in React, which provide an intermediate format for rendering and offer advantages for both client-side and server-side rendering. Server components reduce bundle size on the client and improve search engine optimization. They abstract the rendering process, allowing for faster rendering and flexibility in choosing where to render components. While server components are still in the experimental stage, Next.js is a good starting point to try them out.
Batteries Included Reimagined - The Revival of GraphQL Yoga
GraphQL Galaxy 2021GraphQL Galaxy 2021
33 min
Batteries Included Reimagined - The Revival of GraphQL Yoga
Envelope is a powerful GraphQL plugin system that simplifies server development and allows for powerful plugin integration. It provides conformity for large corporations with multiple GraphQL servers and can be used with various frameworks. Envelope acts as the Babel of GraphQL, allowing the use of non-spec features. The Guild offers GraphQL Hive, a service similar to Apollo Studio, and encourages collaboration with other frameworks and languages.

Workshops on related topic

Introducing FlashList: Let's build a performant React Native list all together
React Advanced Conference 2022React Advanced Conference 2022
81 min
Introducing FlashList: Let's build a performant React Native list all together
Top Content
WorkshopFree
David Cortés Fulla
Marek Fořt
Talha Naqvi
3 authors
In this workshop you’ll learn why we created FlashList at Shopify and how you can use it in your code today. We will show you how to take a list that is not performant in FlatList and make it performant using FlashList with minimum effort. We will use tools like Flipper, our own benchmarking code, and teach you how the FlashList API can cover more complex use cases and still keep a top-notch performance.You will know:- Quick presentation about what FlashList, why we built, etc.- Migrating from FlatList to FlashList- Teaching how to write a performant list- Utilizing the tools provided by FlashList library (mainly the useBenchmark hook)- Using the Flipper plugins (flame graph, our lists profiler, UI & JS FPS profiler, etc.)- Optimizing performance of FlashList by using more advanced props like `getType`- 5-6 sample tasks where we’ll uncover and fix issues together- Q&A with Shopify team
Next.js 13: Data Fetching Strategies
React Day Berlin 2022React Day Berlin 2022
53 min
Next.js 13: Data Fetching Strategies
Top Content
WorkshopFree
Alice De Mauro
Alice De Mauro
- Introduction- Prerequisites for the workshop- Fetching strategies: fundamentals- Fetching strategies – hands-on: fetch API, cache (static VS dynamic), revalidate, suspense (parallel data fetching)- Test your build and serve it on Vercel- Future: Server components VS Client components- Workshop easter egg (unrelated to the topic, calling out accessibility)- Wrapping up
Detox 101: How to write stable end-to-end tests for your React Native application
React Summit 2022React Summit 2022
117 min
Detox 101: How to write stable end-to-end tests for your React Native application
Top Content
WorkshopFree
Yevheniia Hlovatska
Yevheniia Hlovatska
Compared to unit testing, end-to-end testing aims to interact with your application just like a real user. And as we all know it can be pretty challenging. Especially when we talk about Mobile applications.
Tests rely on many conditions and are considered to be slow and flaky. On the other hand - end-to-end tests can give the greatest confidence that your app is working. And if done right - can become an amazing tool for boosting developer velocity.
Detox is a gray-box end-to-end testing framework for mobile apps. Developed by Wix to solve the problem of slowness and flakiness and used by React Native itself as its E2E testing tool.
Join me on this workshop to learn how to make your mobile end-to-end tests with Detox rock.
Prerequisites- iOS/Android: MacOS Catalina or newer- Android only: Linux- Install before the workshop
The Gateway to Backend: A Frontend Developer's Guide to Full-Stack Development
React Summit US 2023React Summit US 2023
160 min
The Gateway to Backend: A Frontend Developer's Guide to Full-Stack Development
Top Content
WorkshopFree
Amy Dutton
Amy Dutton
This workshop will guide you through the product development life cycle of creating a real-world web application. You will learn about React Server Components, building a design system within Storybook, and using frontend development to approach becoming a full-stack developer. The workshop will cover increasing confidence in your application with unit tests and implementing authentication and authorization. You'll have the opportunity to work through product features and examine a real-world RedwoodJS project, gaining valuable experience in real-world product development. RedwoodJS makes it simple to approach full-stack development, and this workshop will give you the skills you need to create your own real-world web applications.
How to Build an Interactive “Wheel of Fortune” Animation with React Native
React Summit Remote Edition 2021React Summit Remote Edition 2021
60 min
How to Build an Interactive “Wheel of Fortune” Animation with React Native
Top Content
Workshop
Oli Bates
Oli Bates
- Intro - Cleo & our mission- What we want to build, how it fits into our product & purpose, run through designs- Getting started with environment set up & “hello world”- Intro to React Native Animation- Step 1: Spinning the wheel on a button press- Step 2: Dragging the wheel to give it velocity- Step 3: Adding friction to the wheel to slow it down- Step 4 (stretch): Adding haptics for an immersive feel
Advanced Application Deployment Patterns with React Server Components (feat. a DIY RSC Framework)
React Summit US 2023React Summit US 2023
104 min
Advanced Application Deployment Patterns with React Server Components (feat. a DIY RSC Framework)
Top Content
WorkshopFree
 Greg Brimble
Greg Brimble
The developer ecosystem is always moving fast and this year has proved no exception. React Server Components can offer a significant improvement to developer experience and to application performance. But I think it's fair to say that this new server-first paradigm can be tricky to wrap your head around!In the first half of this workshop, we'll explore React Server Components from the ground-up: building our own mini meta-framework to help us understand how RSCs work. We'll discover exactly what is produced by an RSC build and we'll connect those pieces together to form a full application.Next, we'll deploy it! Cloudflare have also had a busy year too — Smart Placement, in particular, is a new technology that we've developed which fits the RSC model perfectly. We'll explore why that makes sense for our workshop app, and we'll actually deploy it onto the Cloudflare Developer Platform.Finally, we'll build out our app a little further, using D1 (our serverless SQL database) to really show off the React Server Component's power when combined with Smart Placement.You should come away from this workshop with a greater understanding of how React Server Components work (both behind-the-scenes and also how you as a developer can use them day-to-day), as well as insight into some of the new deployment patterns that are now possible after recent innovations in the platform space.