Hello there! Are you interested in building mobile apps using React Native and Expo? If you are, then you’re in the right place! In this guide, I’ll walk you through the basics of building mobile applications using these two powerful tools. No matter if you’re an experienced developer looking to get into mobile development or a newbie, you’ll be able to follow along with this guide. So, let’s get started! 🚀

What is React Native and Expo?

Before we dive into creating apps, let’s understand what React Native and Expo are. React Native is an open-source mobile application framework that allows developers to build mobile apps using JavaScript and the React library. Expo, on the other hand, is a set of tools and services that simplifies the development process of React Native apps. It provides a variety of built-in components and APIs, as well as development and deployment services, that make the app building process faster and easier. 🤖

A smartphone with a React Native wheel next to it

Setting up your development environment

To start building apps with React Native and Expo, you need to set up your development environment. First, you need to install the React Native CLI and Node.js on your computer. Once you have these installed, you can create a new React Native project by running the following command in your terminal:

npx react-native init MyApp

This will create a new React Native project called “MyApp” in your current directory. Next, you need to install the Expo CLI by running the following command:

npm install -g expo-cli

This will install the Expo CLI globally on your machine. Finally, navigate to your project directory and start the development server by running:

cd MyApp
npm start

This will launch the Expo development server and open the Expo DevTools in your default browser. From the DevTools, you can run your app on a simulator or physical device. 🛠️

A developer working on a computer with a simulator running on screen

Creating your first React Native app

Now that you’ve set up your development environment, it’s time to create your first React Native app using Expo. To do this, navigate to your project directory and run the following command:

expo init MyApp

This will launch an interactive CLI that allows you to choose a project template. Choose “blank” to create a simple project that you can customize later. Once the project is created, navigate into the project directory and start the development server by running:

cd MyApp
npm start

This will launch the app and open it in the Expo client. You can now make changes to the app and see them live in the Expo client. đź“ť

A smartphone with a React Native app running on it

Building a simple app with React Native and Expo

Now that you have your development environment set up and a basic app created, it’s time to build something simple. Let’s say you want to build a simple app that displays a list of books. To do this, you’ll need to use Expo’s built-in components and APIs to create a simple app.

First, create a new component in your project called “BookList.js”. In this component, you’ll create a simple list of books using the FlatList component:

import React from 'react';
import {FlatList, StyleSheet, Text, View} from 'react-native';

const books = [
  {id: '1', name: 'To Kill a Mockingbird', author: 'Harper Lee'},
  {id: '2', name: 'The Great Gatsby', author: 'F. Scott Fitzgerald'},
  {id: '3', name: 'One Hundred Years of Solitude', author: 'Gabriel García Márquez'},
  {id: '4', name: 'Beloved', author: 'Toni Morrison'},
  {id: '5', name: 'The Color Purple', author: 'Alice Walker'},
];

const BookList = () => {
  return (
    <FlatList
      data={books}
      renderItem={({item}) => (
        <View style={styles.item}>
          <Text style={styles.title}>{item.name}</Text>
          <Text style={styles.author}>{item.author}</Text>
        </View>
      )}
      keyExtractor={(item) => item.id}
    />
  );
};

const styles = StyleSheet.create({
  item: {
    backgroundColor: '#f9c2ff',
    padding: 20,
    marginVertical: 8,
    marginHorizontal: 16,
  },
  title: {
    fontSize: 32,
  },
  author: {
    fontSize: 16,
  },
});

export default BookList;

Next, import the BookList component into your App.js file and render it:

import React from 'react';
import {SafeAreaView, StyleSheet} from 'react-native';
import BookList from './BookList';

export default function App() {
  return (
    <SafeAreaView style={styles.container}>
      <BookList />
    </SafeAreaView>
  );
}

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

Finally, run your app and you should see a list of books displayed in your app. Congratulations, you’ve just built your first React Native and Expo app! 🎉

A smartphone with a list of books displayed in a React Native app

Conclusion

In this guide, we’ve covered the basics of building mobile applications with React Native and Expo. We’ve learned what React Native and Expo are, how to set up your development environment, how to create a basic app, and how to build a simple list of books. There’s a lot more you can do with React Native and Expo, so keep exploring and learning new things! 👨‍💻

A person pointing to a smartphone displaying a React Native app

I hope this guide was helpful to you and provided a good understanding of how to get started with React Native and Expo. Happy app building! đź‘‹