Skip to content

React Tutorial

Official Documentation

This tutorial is based on the official React documentation. For the most up-to-date information, visit: https://react.dev/

Welcome to the React tutorial! Learn how to build modern, interactive user interfaces with the world's most popular JavaScript library. This tutorial covers both JavaScript and TypeScript approaches.

What is React?

React is a JavaScript library for building user interfaces, created by Facebook (Meta). It lets you create reusable UI components and efficiently update the DOM when data changes.

┌─────────────────────────────────────────────────────────────┐
│                    How React Works                          │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│   Your Code (JSX/TSX)        Virtual DOM         Real DOM   │
│   ┌─────────────┐          ┌───────────┐       ┌─────────┐ │
│   │ <Button />  │  ─────►  │  React    │ ───►  │ Browser │ │
│   │ <Card />    │  render  │  compares │ patch │   DOM   │ │
│   │ <List />    │          │  changes  │       │         │ │
│   └─────────────┘          └───────────┘       └─────────┘ │
│                                                             │
│   React only updates what's necessary! ⚡                   │
│                                                             │
└─────────────────────────────────────────────────────────────┘

JavaScript vs TypeScript

This tutorial provides examples in both JavaScript and TypeScript:

FeatureJavaScriptTypeScript
File Extension.jsx.tsx
Type SafetyRuntime errorsCompile-time errors
Learning CurveEasierSlightly steeper
IDE SupportGoodExcellent
Industry TrendCommonIncreasingly preferred

Recommendation

If you're new to React, start with JavaScript. If you know TypeScript or want type safety, use TypeScript.

Why Learn React?

FeatureDescription
Component-BasedBuild encapsulated components that manage their own state
DeclarativeDescribe what you want, React figures out how
Virtual DOMEfficient updates for better performance
Huge EcosystemThousands of libraries and tools
Job MarketMost in-demand frontend skill
Learn Once, Write AnywhereReact Native for mobile apps

What You'll Learn

Beginner

Intermediate

  • State - Managing component data
  • Events - Handling user interactions
  • Hooks - useState, useEffect, and more

Advanced

Prerequisites

Before starting this tutorial, you should know:

  • ✅ HTML & CSS basics
  • ✅ JavaScript fundamentals (ES6+)
  • ✅ Basic understanding of the DOM
  • ⭐ TypeScript basics (optional, for TS examples)

New to JavaScript?

Check out our JavaScript Tutorial first!

Quick Preview

jsx
// A simple React component
function Welcome({ name }) {
  return (
    <div className="welcome">
      <h1>Hello, {name}!</h1>
      <p>Welcome to React</p>
    </div>
  );
}

// Using the component
function App() {
  return (
    <div>
      <Welcome name="Developer" />
      <Welcome name="Student" />
    </div>
  );
}
tsx
// Define props interface
interface WelcomeProps {
  name: string;
}

// A typed React component
function Welcome({ name }: WelcomeProps) {
  return (
    <div className="welcome">
      <h1>Hello, {name}!</h1>
      <p>Welcome to React</p>
    </div>
  );
}

// Using the component (type-checked!)
function App() {
  return (
    <div>
      <Welcome name="Developer" />
      <Welcome name="Student" />
    </div>
  );
}

Setting Up Your Environment

JavaScript Setup

bash
# Create a new React app with Vite (JavaScript)
npm create vite@latest my-react-app -- --template react

cd my-react-app
npm install
npm run dev

TypeScript Setup

bash
# Create a new React app with Vite (TypeScript)
npm create vite@latest my-react-app -- --template react-ts

cd my-react-app
npm install
npm run dev

Your app will be running at http://localhost:5173

Project Structure

my-react-app/
├── node_modules/
├── public/
│   └── vite.svg
├── src/
│   ├── App.css
│   ├── App.jsx          ← Main component
│   ├── index.css
│   └── main.jsx         ← Entry point
├── index.html
├── package.json
└── vite.config.js
my-react-app/
├── node_modules/
├── public/
│   └── vite.svg
├── src/
│   ├── App.css
│   ├── App.tsx          ← Main component (.tsx)
│   ├── index.css
│   ├── main.tsx         ← Entry point (.tsx)
│   └── vite-env.d.ts    ← Type declarations
├── index.html
├── package.json
├── tsconfig.json        ← TypeScript config
└── vite.config.ts

Video Tutorials

Recommended Video Resources

Learn React through these excellent video tutorials from the community.

Free Courses

CourseCreatorDescription
React Course for BeginnersfreeCodeCamp12-hour comprehensive beginner course
React Tutorial for BeginnersProgramming with Mosh1-hour crash course
React JS Full CourseDave Gray9-hour complete course
React in 100 SecondsFireshipQuick 100-second explanation

Official Resources

ResourceDescription
React.dev LearnOfficial React documentation with interactive tutorials
React.dev TutorialBuild Tic-Tac-Toe step by step

Topic-Specific Videos

TopicVideoDuration
React HooksReact Hooks Tutorial~30 min
React RouterReact Router v6 Tutorial~30 min
State ManagementRedux Toolkit Tutorial~2 hours
TypeScript + ReactReact TypeScript Tutorial~1 hour

Let's Begin!

Ready to start building with React? Head over to the Getting Started guide!


Get Started →