Short-Video App with React Native and Supabase · Course book
Chapter 2: Starting with Expo
Every mobile project begins with the same question: how do I get code running on a phone quickly, and keep it running as the project grows? For React Native, the most common answer today is Expo. This chapter explains what React Native and Expo are and how they divide the work, why Expo suits a media-heavy social app, how a new project is created and what each generated file does, how to strip the starter template down to a clean base, how to read and fix the errors that inevitably appear, and how the first tabs and routes are laid out ready for styling in the next chapter. Along the way it explains version numbers and why Expo's install command matters, with a worked example.
React Native and Expo
React Native lets you write an app with React components in JavaScript or TypeScript, and renders them as real native views on iOS and Android rather than as a web page. A <View> becomes a native container and a <Text> a native text label. Your code runs in a JavaScript engine on the phone and talks to the native side, which draws the interface and provides device features.
A plain React Native project requires you to manage the native iOS and Android projects yourself, with Xcode and Android Studio, every time you add a library with native code. Expo is a framework and set of tools on top of React Native that removes most of that burden. It provides a curated set of libraries, known as the Expo SDK, for the camera, video playback, image picking, file system, notifications and much more, all tested to work together; a development server; an app called Expo Go that runs your project on a real phone by scanning a QR code; and cloud build services that produce the files submitted to app stores.
| Task | Bare React Native | With Expo |
|---|---|---|
| Start a project | Generate native iOS and Android folders | One command; native folders are generated only when needed |
| Run on a phone | Build and install through Xcode or Android Studio | Scan a QR code with Expo Go, or use a development build |
| Camera, video, image picker | Find, install and configure separate libraries | Install matching Expo SDK packages |
| Navigation | Configure a navigation library by hand | Expo Router creates routes from files |
| Build for the stores | Local builds with signing set up by hand | Cloud builds and submission with EAS |
For an app that relies on the camera, video playback and media uploads, the Expo SDK is a major advantage: these are exactly the features that are fiddly to configure natively. Expo does not lock you in, either. If a project later needs custom native code, Expo can generate the native folders and you continue from there.
Creating the project
A new project is created with npx create-expo-app followed by a name. The command downloads a starter template, installs dependencies and sets up TypeScript and Expo Router. Running npx expo start launches the development server, which prints a QR code. Scanning it with Expo Go on a phone connected to the same network loads the app; pressing i or a opens an iOS simulator or Android emulator if one is installed. Saving a file updates the app within a second or two, thanks to Fast Refresh, which keeps component state where it can.
The generated project contains a handful of important files and folders.
app/holds the screens. With Expo Router, every file here is a route, and folders create nested routes.app/_layout.tsxis the root layout that wraps every screen, the natural place for providers such as authentication.app.jsonholds the app's configuration: its name, icon, splash screen, permissions messages and plugins.package.jsonlists the dependencies and scripts;tsconfig.jsonconfigures TypeScript.assets/holds images and fonts, andcomponents/reusable pieces.
The starter template includes example screens, components and assets to show what is possible. A clean project is easier to understand, so the first job is removing them. The template provides a reset script that moves the examples aside and leaves a minimal app folder; alternatively, delete the example files by hand and remove the imports that referred to them.
A few habits make the project easier to work on from the first day. Put it under version control with Git straight away and commit the clean starting point, so you can always return to a working state. Keep secrets such as API keys out of the code, in an environment file listed in .gitignore; Expo reads variables whose names begin with EXPO_PUBLIC_ into the app. Decide on a folder layout for components, hooks and helper functions, and use TypeScript's checks rather than ignoring them, because a type error caught in the editor is far cheaper than a crash on a tester's phone.
Installing packages and version numbers
Libraries are added with npx expo install rather than plain npm install. The difference matters. Each Expo SDK release is tested with particular versions of many libraries, and expo install picks the version compatible with your project's SDK, while a plain install takes the newest version, which may expect a newer SDK and crash at run time.
Version numbers follow semantic versioning: MAJOR.MINOR.PATCH. A patch release fixes bugs, a minor release adds features without breaking anything, and a major release may break existing code. In package.json, a caret or tilde before a version sets which updates are allowed.
"^2.4.1". The caret allows any version from 2.4.1 up to, but not including, 3.0.0, so 2.4.9 and 2.9.0 are accepted but 3.0.0 is not. Listed as "~2.4.1", the tilde allows only patch updates, from 2.4.1 up to but not including 2.5.0, so 2.4.9 is accepted but 2.5.0 is not. Expo's install command often writes tilde ranges, so the library stays on the minor version tested with your SDK while still receiving bug fixes.When upgrading the Expo SDK itself, Expo provides a command that upgrades the SDK and updates all the related packages together. Upgrading one library at a time, outside that process, is a common cause of mysterious errors. Expo also offers a doctor command that checks the project for mismatched versions and common configuration problems, a quick first step when something breaks.
Reading and fixing errors
Errors appear constantly while setting up, and learning to read them is half the skill. In React Native they arrive in three places. The terminal running the development server shows bundling errors, such as a missing file or a syntax mistake, with the file name and line number. The phone shows a red screen for errors that happen while the app runs, with a stack trace pointing to the component. And yellow warnings flag problems that do not stop the app, such as deprecated features.
A few fixes solve most early problems. If the app cannot find a module after installing a package, stop the server and restart it with the cache cleared, using npx expo start --clear. If an import fails after deleting template files, search for the old file name and remove the import. If Expo Go reports that the project needs a newer or older version, check that the phone's Expo Go matches the project's SDK. If changes do not appear, check that the phone and computer are on the same network, or use the tunnel connection option. Reading the first line of an error message carefully, rather than the whole stack trace, usually reveals the cause.
First tabs and routes
With Expo Router, navigation follows the folder structure. A folder name in parentheses, such as (tabs), is a route group: it organises files without adding a segment to the address. Inside it, a _layout.tsx that returns a Tabs component turns each file in the folder into a tab.
A short-video app needs five tabs: Home for the feed, Friends, a central Camera button, Inbox and Profile. Each screen can start as a simple component returning a centred title, which proves the navigation works before any real content exists. Pages outside the tabs, such as the login screen, live in another group, so that the tab bar is hidden while signing in. The next chapter adds the styling system and fills out these routes, including the authentication group.
Practice tasks
- Which of these versions satisfy
"^1.8.3": 1.8.2, 1.8.9, 1.12.0, 2.0.0? Which satisfy"~1.8.3"? - Explain why
npx expo installis safer thannpm installin an Expo project. - After deleting the template's example files, the bundler reports "Unable to resolve module". Describe how you would find and fix the cause.
- Draw the folder structure that produces tabs for Home, Discover and Profile, plus a login screen without a tab bar.
- What is a route group, and why does its name not appear in the address of its screens?
- List three things
app.jsonconfigures, and say why permission messages belong there.
This course book is available to read online only at tech-academy.chrysolites.org.