React Native — Introduction
Reason why react native is in demand :
- Cross-platform framework : It allows us to develop application for iOS and Android by writing single code.
- Open source : Though react native is developed by facebook team, it is open source, so anyone can contribute to the community. Whether it is bug fixing or new feature updates.
- Supports native code : At any point of time if there is no support or feature update from react native, we can write native code and call it from react native application.
Apart from these benefits we can also build part of our application with react native, it is not necessary to build whole application with react native. Now let’s see how to get started with react native development.
There are 2 ways to develop react native applications :
npm install -g expo-cli
You can follow official react native guideline to setup expo-cli.
2. Using React Native cli : It will help you to develop react native application with native code support. It allows you to write native module also for Android and iOS. If you are using react native in existing native application, you need to follow react native cli guideline.However installation is same as Expo cli, you just need to use command
npm install -g react-native-cli
For detailed setup you can follow “Building Project With Native Code” tab in official document.
In this tutorial we will use react native cli to create our first hello world application.
Creating First React Native Application
Step 1 : After done with the above steps you are now having react native in your system. Open command prompt/terminal in your system and write below command to create our first project called HelloWorld with react native.
react-native init HelloWorld
It will create folder called HelloWorld which will contain basic files which are needed to run react native application like below :
Step 2 (Optional) : If you find node_modules in your HelloWorld directory, there is no need to follow this step. In earlier react native version we have to install node_modules by using following commands.
Step 3 : Final step is to run your application using either of the following commands.
Note : Before running above commands, make sure you have all the native setup available in your system, otherwise it will not run your application in given platform. Here is the reference link to setup android platform. For iOS you can follow default iOS development guideline which requires you to install xcode in your mac machine.
If there is no error in setup, you will be able to see your first react native project output.
In next tutorial we will see how to code with react-native, how react-native works and how to modify code to perform some user actions.
Originally published at Android Gig.