Project 90 of 100 - React Native Starter
Tags: reactnative, react, javascript, typescript
Published: 2022-01-02 05:15:40

*Hey! I'm on a mission to make 100 React.js projects. Please follow my dev.to profile or my [twitter](https://www.twitter.com/jwhubert91) for updates and feel free to reach out if you have questions. Thanks for your support!*

React Native is one of the most popular cross-platform development frameworks. That is, it allows you to write React code that runs on both Android and iOS. They also have plans to expand further, into web apps and desktop. I recently started an online course that teaches React Native so I'll likely have a few projects based on it.

For today's project I decided to simply follow along with the [React Native docs](https://reactnative.dev/) and boot up a sample project. This is easily enough done especially if you're already familiar with React (which you should be before embarking to learn React Native). There are a few interesting fundamentals happening under the hood though.

###Under the Hood
First, there are essentially two ways to boot up and run a React Native project. One uses pure React Native code, which requires the actual use of native iOS and Android libraries to run. This is no different from how your code will run on a real mobile device when you ship.

The second, preferred, way to initialize a React Native app is using a CLI tool called Expo, which was specifically developed to help React Native developers code and test quickly. I tried both, but am very impressed with Expo so I'll describe that method, because it's fast and recommended. You can read more about it [here](https://docs.expo.dev/).

###The CLI Commands
Make sure you have the latest stable version of Node installed on your machine. Or at least make sure it's past version 12 which includes support for Expo. For more detail you can check the Expo method React Native docs [here](https://reactnative.dev/docs/environment-setup).

With Node installed, you can now install the Expo CLI tool with the following line in the command line:

```
npm install -g expo-cli
```

Now Expo is installed. Expo was written specifically to help generate and test React Native so you'll be surprised at how easy it now is to generate a React Native starter app that isn't unlike Create React App. In your command line, simply enter the following line:

```
expo init reactNativeStarter
```

It will generate a list of options like so:
![Printout of command line options for Expo projects](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4fbbmebrtyhnhh4eqvpp.png) 

Much like Create React App, Expo can generate all the files necessary to run a React Native app and serves the application for you. You will, however, need to pick what sort of template you want. Ignore the Basic option for now. To start, you want Managed (this lets Expo handle serving the application). Among the Managed options, you can currently choose between a Javascript project, a Typescript project, and a Javascript project with multiple views and some built-in libraries. I'm going to choose Typescript.

That will create all the files you need for a barebones React Native project with Typescript. If you open it up in your code editor, the App.tsx file will look like the following:

![Project opened in VSCode](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iuhg7uk0ut8vz8029u0u.png)

Lastly, to get the app running you need to navigate into the project directory in your command line and run `npm start` (or `yarn start` if that's your thing). Expo will now spit out a lot of info in the command line for you.

###Running Your Project
In your terminal or command line, Expo should now be running on a local port on your machine. You should have a lot of information up like this:

![Printout of Expo code running on Mac command line terminalk](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/azr9qmvjjjjjx4q1t3ie.png)

If you find the line which says `Developer tools running on...` and copy the localhost address and paste it in your browser, you'll now have access to the very handy Expo developer tools. That screen will look like this, with the same QR code as the command line:

![Screenshot of Expo Developer tools](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zz7k8b7iy7mb85scfa93.png)

As much as I work in the command line (Terminal on Mac), I do love a nice GUI and this little GUI for running React Native applications with status update and a QR code for easy access is really accessible in my opinion. 

To actually see your React Native project running on a mobile device of your choice you can get out your phone, download the [Expo Go app](https://expo.dev/client). This is an app that lets you run React Native code in Expo on your phone. After installing, you can simply scan the QR code in your command line or the Expo dev tools in your browser, and follow the prompt to launch the project in Expo on your phone!

###Modifying Your App
Your app is now running on Expo and you should be able to see it on your device. Just to get a taste of what it's like to write React Native code, go back to your code editor and change the text inside the `<Text></Text>` elements. The app should update immediately without you having to do anything on your device.

**If you like projects like this and want to stay up to date with more, check out my Twitter [@jwhubert91](https://twitter.com/jwhubert91), I follow back! See you tomorrow for another project.**