In this guide, we’ll take a closer look at React Native. You’ll learn the absolute basics of getting started with it. Specifically, we’ll cover the following:
- what is React Native
- what is Expo
- how to set up an React Native development environment
- how to create an app with React Native
What is React Native?
Another advantage of React Native is its ability to access native device features. There are many plugins which you can use to access native device features, such as the camera and various device sensors. If you’re in need of a platform-specific feature that hasn’t been implemented yet, you can also build your own native modules — although that will require you to have considerable knowledge of the native platform you want to support (Java or Kotlin for Android, and Objective C or Swift for iOS).
What is Expo?
Before coming here, you might have heard of Expo. It’s even recommended in the official React Native docs, so you might be wondering what it is.
In simple terms, Expo allows you to build React Native apps without the initial headache that comes with setting up your development environment. It only requires you to have Node installed on your machine, and the Expo client app on your device or emulator.
But that’s just how Expo is initially sold. In reality, it’s much more than that. Expo is actually a platform that gives you access to tools, libraries and services for building Android and iOS apps faster with React Native. Expo comes with an SDK which includes most of the APIs you can ask for in a mobile app development platform:
Those are just few of the APIs you get access to out of the box if you start building React Native apps with Expo. Of course, these APIs are available to you as well via native modules if you develop your app using the standard React Native setup.
Plain React Native or Expo?
The real question is which one to pick up — React Native or Expo? There’s really no right or wrong answer. It all depends on the context and what your needs are at the moment. But I guess it’s safe to assume that you’re reading this tutorial because you want to quickly get started with React Native. So I’ll go ahead and recommend that you start out with Expo. It’s fast, simple, and easy to set up. You can dive right into tinkering with React Native code and get a feel of what it has to offer in just a couple of hours.
That said, I’ve still included the detailed setup instructions for standard React Native for those who want to do it the standard way. As you begin to grasp the different concepts, and as the need for different native features arises, you’ll actually find that Expo is kind of limiting. Yes, it has a lot of native features available, but not all the native modules that are available to standard React Native projects are supported.
Note: projects like unimodules are beginning to close the gap between standard React Native projects and Expo projects, as it allows developers to create native modules that works for both React Native and ExpoKit.
Setting Up the React Native Development Environment
In this section, we’ll set up the React Native development environment for all three major platforms: Windows, Linux, and macOS. We’ll also cover how to set up the Android and iOS simulators. Lastly, we’ll cover how to set up Expo. If you just want to quickly get started, I recommend that you scroll down to the “Setting up Expo” section.
Here are the general steps for setting up the environment. Be sure to match these general steps to the steps for each platform:
- install JDK
- install Android Studio or Xcode
- install Watchman
- update the environment variable
- install the emulator
- install Node
- install React Native CLI
You can skip to the section relevant to your operating system. Some steps — like setting up Android Studio — are basically the same for each operating system, so I’ve put them in their own section:
- setting up on Windows
- setting up on Linux
- setting up on macOS
- setting up Android Studio
- install Node
- setting up Expo
- setting up emulators
- install React Native CLI
- troubleshooting common errors
Setting Up on Windows
This section will show you how to install and configure the software needed to create React Native apps on Windows. Windows 10 was used in testing for this.
Windows doesn’t really come with its own package manager that we can use to install the needed tools. So the first thing we’ll do is install one called Chocolatey. You can install it by executing the following command on the command line or Windows Powershell:
@"%SystemRoot%System32WindowsPowerShellv1.0powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%chocolateybin"
We can now install the other tools we need by simply using Chocolatey.
Python comes with the command line tools required by React Native:
choco install -y python 2
The JDK allows your computer to understand and run Java code. Be sure to install JDK version 8 as that’s the one required by React Native:
choco install jdk8
Node has an installer for Windows. It’s better to use NVM for Windows, as that will enable you to install multiple versions of Node so that you can test new versions, or use a different version depending on the project you’re currently working on. For that, you can use NVM for Windows. Download nvm-setup.zip, extract it and execute
nvm-setup.exe to install it.
Watchman optimizes the compilation time of your React Native app. It’s an optional install if you’re not working on a large project. You can find the install instructions on their website.
Update the Environment Variables
This is the final step in setting up React Native on Windows. This is where we update the environment variables so the operating system is aware of all the tools required by React Native. Follow these steps right before you install the React Native CLI.
Go to Control Panel → System and Security → System. Once there, click the Advanced system settings menu on the left.
That will open the system properties window. Click on the Environment Variables button:
Under the User variables section, highlight the Path variable and click the edit button.
On the edit screen, click the New button and enter the path to the Android SDK and platform tools. For me, it’s on
C:usersmyUsernameAppDataLocalAndroidSdkplatform-tools. Note that this is also where you add the path to the JDK if it isn’t already added:
Source: Site Point
Republished by Blog Post Promoter