VOOZH about

URL: https://www.geeksforgeeks.org/react-native/expo-router-and-context-setup-in-react-native/

⇱ Expo Router and Context Setup in React Native - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Expo Router and Context Setup in React Native

Last Updated : 20 Jan, 2026

To build a scalable React Native app with Expo, it’s essential to structure your project cleanly, set up navigation, and manage shared state efficiently. This guide briefly covers how routing and context come together to form a solid application foundation.

  • Project Structure: Organize code using a src folder with separate screens and contexts for better maintainability.
  • Routing Setup: Implement navigation using a stack-based router to handle screen transitions smoothly.
  • Global State: Use React Context to manage and share state across multiple screens without prop drilling.

Implementing Routing and Global Context

It involves configuring screen navigation and managing shared application state using routing and React Context.

Step 1: Set Up a New Expo Project

Start by creating a new Expo project using the Expo CLI:

expo init ExpoRouterContextApp

Follow the prompts to set up your project.

Step 2: Install Necessary Dependencies

Navigate to your project directory and install the required dependencies:

cd ExpoRouterContextAppnpm install @react-navigation/native @react-navigation/stack react-native-gesture-handler

Note: Expo handles most native configuration automatically.

Step 3: Create a Basic Folder Structure

Inside your project directory, create a src folder. Within the src folder, create screens and contexts directories:

mkdir srccd srcmkdir screens contexts

Step 4: Implement a Router Using React Navigation

Create a Router.js file inside the src directory and implement a basic stack navigator using React Navigation:

Step 5: Set Up a Context Provider for Global State Management

Create a GlobalContext.js file inside the contexts directory to manage global state using React context:

Step 6: Create Screens

Inside the screens directory, create HomeScreen.js and DetailScreen.js files with some basic content:

Step 7: Integrate Router and Context Provider in App.js

Finally, integrate the router and context provider in your App.js file:


Final Outcome

This setup results in a well-structured React Native application with smooth navigation, shared state management, and improved scalability.

  • Expo handles the app lifecycle and environment.
  • React Navigation manages screen transitions.
  • Context API provides global state.
  • Clean folder structure improves scalability and maintainability.
Comment
Article Tags:

Explore