React Native - Why React Native? Let’s Build Our First “Hello World” App
Why React Native? Let’s Build Our First “Hello World” App
Have you ever wished you could use your web development skills to build a mobile app without learning multiple languages like Java, Kotlin, or Swift? That’s exactly where React Native comes in. Created by Facebook (now Meta), React Native allows you to build native mobile apps for both iOS and Android using JavaScript and the same principles you know from React.js.
In this first post of our React Native series, I’ll introduce the core benefits of React Native and walk you through creating a simple “Hello World” app. If you’ve built websites with React.js, you’ll feel right at home!
1. What Is React Native?
React Native is a framework for building mobile applications using React. Instead of rendering web components, it renders real native UI elements, making your app look and perform like a traditional, fully native application.
Key benefits include:
Cross-Platform: Write once, run on both iOS and Android (and more, with community projects).
Hot Reloading: See changes in real-time without losing your app’s state.
Large Ecosystem & Community: Tons of third-party libraries, tutorials, and active community support.
Shared Codebase: Saves development time since most of your code (and knowledge) can be shared across platforms.
2. Setting Up Your Environment
There are two popular ways to get started:
Expo CLI: Easiest setup, comes with a suite of tools for development, testing, and deployment. Ideal for beginners.
React Native CLI: More control, closer to native development. Recommended for more advanced setups or when adding custom native modules.
For this tutorial, we’ll use Expo because it’s straightforward, especially for beginners.
Prerequisites:
Node.js installed (v14 or above is typically recommended).
Expo CLI globally installed:
npm install --global expo-cli
A text editor (VS Code, WebStorm, etc.).
An iOS or Android device simulator/emulator, or the Expo Go app on your phone.
Create Your First “Hello World” App
- Initialize the Project
In your terminal, run:
- Initialize the Project
npx create-expo-app HelloWorld
This command sets up a new React Native app with Expo.
2.Navigate & Start
cd HelloWorld
npx expo start
This opens the Expo development tools in your browser. You can scan the QR code with the Expo Go app on your phone, or run the app in an emulator/simulator.
- Explore the Project Structure
Inside your project folder, you’ll notice:
App.js
: The main entry point of your app.package.json
: Lists dependencies and scripts.assets
folder: Contains images or other static resources.4. Edit
App.js
Let’s customize the default code to display “Hello World.” You can replace the code inApp.js
with the following snippet:import React from 'react'; import { StyleSheet, Text, View } from 'react-native'; export default function App() { return ( <View style={styles.container}> <Text style={styles.title}>Hello World!</Text> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: '#f0f8ff', }, title: { fontSize: 32, fontWeight: 'bold', color: '#333', }, });
What’s happening here?
View
is like a<div>
in web—used for layout.Text
is a special component for displaying text in React Native.StyleSheet
organizes your styles in a React Native-friendly way.
As soon as you save App.js
, Expo will automatically reload the app in the simulator or on your physical device, displaying the “Hello World!” text. Congrats, you’ve just built your first React Native app!
Stay tuned! React Native can open up a whole new world of possibilities for your development projects. If you have any questions or run into setup issues, feel free to leave a comment. Let’s build something amazing together—one step at a time.