Build a Stunning Weather App with React Native: A Step-by-Step Beginner’s Guide

5.79K 0 0 0 0

📘 Chapter 1: Setting Up React Native and Your Development Environment

🧭 What You’ll Learn

By the end of this chapter, you will:

  • Understand the difference between Expo CLI and React Native CLI
  • Set up your system for React Native development
  • Create and run your first React Native app
  • Understand the folder structure of a typical project
  • Prepare for building a real weather app

️ What Is React Native?

React Native is a JavaScript framework developed by Facebook that lets you build mobile apps using React and native platform components. You write your UI in JavaScript, and it compiles to native iOS and Android code.

Unlike traditional mobile development (Swift for iOS and Java/Kotlin for Android), React Native lets you build for both platforms with a single codebase.


🚀 Choosing Your Development Setup: Expo CLI vs React Native CLI

CLI Type

Expo CLI (Recommended for Beginners)

React Native CLI (Advanced/Flexible)

Setup Complexity

Simple, all-in-one

Complex, manual setup

Native Modules

Limited, unless you eject

Full native access

Build Tools

Expo Go app or EAS

Xcode (iOS), Android Studio (Android)

Best For

Rapid prototyping, small/medium apps

Advanced apps needing full native control

We’ll use Expo CLI for this weather app because it simplifies setup and works great for API-based projects.


🖥 System Requirements

Platform

Requirements

Windows

Node.js, Git, Expo CLI, Android emulator

macOS

Node.js, Git, Xcode (for iOS), Expo CLI

Linux

Node.js, Git, Expo CLI

Make sure you have Node.js v14+, npm or yarn, and Git installed.


🔧 Step-by-Step Setup Guide Using Expo CLI


Step 1: Install Node.js and Git

Download and install Node.js. It comes with npm.

Then install Git:


Step 2: Install Expo CLI

Open terminal and run:

bash

 

npm install --global expo-cli

Check installation:

bash

 

expo --version


Step 3: Create Your First Project

bash

 

expo init WeatherApp

Select the blank template (JavaScript) when prompted.

bash

 

cd WeatherApp

expo start

This opens Expo DevTools in your browser.


Step 4: Run Your App

📱 On Real Device:

  1. Install Expo Go from Play Store or App Store
  2. Scan the QR code from your terminal/browser using Expo Go app
  3. App runs instantly on your phone

💻 On Emulator:

  • Android: Open Android Studio > Virtual Device Manager > Start emulator
  • iOS (macOS only): Run npm run ios or open the iOS simulator from Xcode

📁 Understanding Project Structure

Here’s a breakdown of what expo init generates:

File/Folder

Purpose

App.js

Entry point and main UI code

package.json

Manages dependencies and project metadata

assets/

Image and font resources

node_modules/

Installed packages

.gitignore

Files/folders Git should ignore

babel.config.js

JavaScript transpilation settings


🔨 Editing Your First Component

Open App.js in your code editor (VS Code recommended).

Replace it with:

jsx

 

import React from 'react';

import { View, Text, StyleSheet } from 'react-native';

 

export default function App() {

  return (

    <View style={styles.container}>

      <Text style={styles.title}>🌤️ Weather App Starter</Text>

    </View>

  );

}

 

const styles = StyleSheet.create({

  container: {

    flex: 1,

    backgroundColor: '#87ceeb',

    alignItems: 'center',

    justifyContent: 'center',

  },

  title: {

    fontSize: 24,

    color: '#fff',

  },

});

Save the file. Your app updates automatically with hot reload.


🚨 Common Setup Errors & Fixes

Error Message

Solution

expo: command not found

Run npm install -g expo-cli

Emulator not showing app

Ensure emulator is running before expo start

White screen / blank page

Check for typos or JS errors in App.js

QR code not scanning

Ensure phone and PC are on the same Wi-Fi network


💡 Developer Tips for Efficient Setup

  • Use VS Code with the React Native Tools extension
  • Keep Expo Go updated on your phone
  • Run npm start -c to clear Expo cache
  • Use component-based file structure for cleaner code organization
  • Learn keyboard shortcuts for quicker development

🔗 Optional: Using React Native CLI (Advanced Users)

If you prefer full control, you can use React Native CLI:

bash

 

npx react-native init WeatherAppCLI

cd WeatherAppCLI

npx react-native run-android

You'll need to install Xcode for iOS and Android Studio with SDK tools for Android.


🚀 Next Steps: Ready to Build

You now have:

  • React Native (Expo) set up on your system
  • Your first project created and running
  • An understanding of app structure and how to edit components
  • Expo DevTools and mobile device or emulator working


In the next chapter, we’ll begin designing the UI of the weather app, starting with a search input, temperature display, and condition layout.

Back

FAQs


❓1. Do I need to know React to build a React Native weather app?

Answer:
While React Native shares many concepts with React (like components, props, and state), you don’t need to be an expert in React to start. Basic knowledge of JavaScript and understanding of components will help you get going quickly.

❓2. What’s the difference between Expo and React Native CLI?

Answer:
Expo is a framework and platform that simplifies React Native development. It’s great for beginners.
React Native CLI provides full native access and is preferred for advanced, production-grade apps. For this weather app, Expo is usually enough.

❓3. Which weather API should I use?

Answer:
You can use any public weather API, but OpenWeatherMap is beginner-friendly, well-documented, and offers a free tier with real-time weather data, making it ideal for this project.

❓4. Is this weather app cross-platform?

Answer:
Yes! React Native apps work on both Android and iOS. You’ll be building one codebase that runs on both platforms with native-like performance.

❓5. Can I use geolocation to show weather for the current location?

Answer:
Absolutely. React Native supports location access through packages like expo-location or react-native-geolocation-service, which lets you fetch the user’s coordinates and use them in your API requests.

❓6. Do I need to pay for an API key?

Answer:
No. Most APIs like OpenWeatherMap offer a free tier that includes current weather data, which is enough for this app. Just sign up and grab your API key from their dashboard.

❓7. How do I manage the app’s state?

Answer:
This app uses React Hooks—mainly useState for managing input and weather data, and useEffect for API calls. For more advanced apps, you might consider using context or libraries like Redux.

❓8. How do I style the UI in React Native?

Answer:
React Native uses the StyleSheet.create() method to define CSS-like styles. You can also use Flexbox for layout and third-party libraries like react-native-elements or styled-components for more flexibility.

❓9. Can I deploy this app to the Google Play Store or Apple App Store?

Answer:
Yes, with additional steps. You’ll need to create a developer account for each store, build release versions, test thoroughly, and follow each platform’s publishing guidelines. Expo also offers services like EAS Build to simplify deployment.

❓10. What else can I add to make the app more advanced?

Answer:
You can add features like:

  • 7-day weather forecasts
  • Hourly breakdowns
  • Save favorite cities
  • Background images based on weather
  • Dark mode support
  • Weather animations (e.g., rain, sun, snow)


These upgrades help turn a simple app into a portfolio-level project.