How to Set Up React Native with Expo πŸš€


How to Set Up React Native with Expo πŸš€

React Native with Expo makes it easy to build mobile applications using JavaScript and React. Expo provides a managed workflow, eliminating the need to install native dependencies manually. In this guide, you'll learn how to set up React Native with Expo step by step.



1. Install Node.js and npm

Before setting up Expo, ensure that you have Node.js installed on your system. You can download it from: https://nodejs.org/

Once installed, verify the installation by running:

node -v  # Check Node.js version
npm -v   # Check npm version

2. Install Expo CLI

Expo CLI is the command-line tool used to manage your Expo projects. Install it globally using npm or yarn:

npm install -g expo-cli

OR

yarn global add expo-cli

3. Create a New Expo Project

Now, create a new React Native project using Expo:

npx create-expo-app myApp

Navigate to the project folder:

cd myApp

4. Start the Development Server

To start the Expo development server, run:

npx expo start

This will open a web interface where you can scan a QR code using the Expo Go app to preview your app.

5. Install Expo Go

Download the Expo Go app on your mobile device to test your application:

6. Running the App on Your Device

  1. Open Expo Go on your phone.
  2. Scan the QR code displayed in the terminal or Expo web interface.
  3. Your React Native app will run instantly!

7. Modify Your App

Open App.js in a text editor and modify the code to see live updates. Example:

import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';

export default function App() {
  return (
    <View style={styles.container}>
      <Text>Hello, Expo!</Text>
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

Save the file, and the changes will appear instantly in the app.

8. Build and Publish Your App

To build a production-ready app:

  • Run npx expo prebuild if you want to eject to a bare React Native project.
  • Use npx expo build to create an APK or IPA for publishing.
  • Publish your app using npx expo publish.

Expo simplifies React Native development by removing the complexity of setting up native dependencies. With Expo, you can quickly prototype, test, and deploy mobile apps efficiently.

 

Comments

Popular posts from this blog

Fetching Data from an API in React Native with Expo

State Management in React Native with Expo: A Beginner’s Guide