Say “Hello World” with a React Native App

Steps to making an app with React Native to print the word “Hello World”

Introduction

What is REACT NATIVE?

React Native helps you to create real-time mobile apps with the help of javascript alone, which is supportable for both Android and iOS platforms. Just by coding once, the REACT Native apps are available for both iOS and Android platforms which helps in saving development time.

React Native is a framework that builds a hierarchy of UI components to build the JavaScript code. It has a set of components for both iOS and Android platforms to build a mobile application with the native look and feel.
It has a great popularity, backed by Facebook and has a huge community support today.

 

Why is it used?

React Native is widely used for the following reasons :

  • Code once :
    One of the most important reasons why React native is used is because developers have to write just one set of javascript code to enjoy the performance of the React Native mobile applications
  • Cross-platform usage :
    React native has gained popularity because React native apps can be developed for both IOS and ANDROID by using a single codebase for both platforms.
  • Better performance :
    React native apps are compiled into natively written code. This enables it to work on both operating systems as well as enables it to function the same way on both platforms with no lags at all.
  • Other benefits :
    Other benefits of React native framework includes faster development, ability to reuse components and ease to be maintained.

 

Steps to create a React Native app

The following are the steps to create a React native app that is used to print the word “Hello World ”


Step 1: Project setup

An application created using react native can be run on mac, windows and Linux machines.

In this article, we will focus on creating a React Native app on LINUX.
Also, we could create an android as well as an IOS application using react native.

In this article, we will focus on creating an android application using react native.

To create an application using react native we need to install React Native on our computer.
However, there are some prerequisites before installing react native on our computer.

We need to install the latest version of NODE and NPM before installing react native on our computer.
React native cli is installed using NPM.

We need to run the following command in the command prompt or shell.

npm install -g react-native-cli
To create an Android application  we need to install the following

 

  • JDK 8 OR newer version.
  • Android SDK.

We need an Android development environment to write an android application using react native.

 

We also need to need to Configure the ANDROID_HOME environment variable to write an android application using React native.

 

Similarly to write an IOS application, we need to configure the IOS environment variable.

 

The project setup is now ready. We can now write an android application using React native on our LINUX machine.

 


Step 2: Creating a new application

Run the following command in the command prompt to create a project named helloworldaqb.

react-native init HelloWorldAqb

 

 

Step 3: Writing Code to print “Hello World ”
Inside the project, folder helloworldaqb edit the app.js file, remove the entire existing code, and place the following code inside it.

 

[sourcecode language=”js”]
import React, { Component } from ‘react’;
import { Text, View } from ‘react-native’;

export default class App extends Component {
render() {
return (
<View>
<Text>
Hello World
</Text>
</View>
);

}
}

[/sourcecode]


Step 4: Running the application


You can now connect your real device.
Run the following commands in the command prompt to run the application.

 

  • cd helloworldaqb

 

  • react-native run-android