Module 1: React Fundamentals

Learn React fundamentals including JSX syntax, components, props, and React developer tools. Start your React journey with this comprehensive module.

Back to Course|4.5 hours|Beginner

React Fundamentals

Learn React fundamentals including JSX syntax, components, props, and React developer tools. Start your React journey with this comprehensive module.

Progress: 0/5 topics completed0%

Select Topics Overview

React Fundamentals

Learn the core concepts of React and understand why it's the most popular frontend library

Content by: Praveen Kumar

MERN Stack Developer

Connect

What is React?

React is a JavaScript library for building user interfaces, particularly single-page applications. It's used for handling the view layer and can be used for developing both web and mobile applications.

Key Features of React

  • •Component-Based: Build encapsulated components that manage their own state
  • •Declarative: Create interactive UIs and efficiently update and render components
  • •Learn Once, Write Anywhere: Develop new features without rewriting existing code
  • •Virtual DOM: Efficient rendering and better performance

Why Choose React?

  • •Popular: Used by Facebook, Instagram, Netflix, and many other companies
  • •Large Community: Extensive ecosystem and third-party libraries
  • •Job Market: High demand for React developers
  • •Performance: Fast rendering with Virtual DOM

React vs Other Frameworks

Code Example
// React - Component-based approach
function Welcome(props) {
  return <h1>Hello, {props.name}!</h1>;
}

// Angular - Template-based approach
@Component({
  selector: 'app-welcome',
  template: '<h1>Hello, {{name}}!</h1>'
})
export class WelcomeComponent {
  @Input() name: string;
}

// Vue.js - Template-based approach
<template>
  <h1>Hello, {{ name }}!</h1>
</template>
<script>
export default {
  props: ['name']
}
</script>
Swipe to see more code

React Development Setup

Code Example
// Create React App (CRA)
npx create-react-app my-react-app
cd my-react-app
npm start

// Vite (Modern alternative)
npm create vite@latest my-react-app -- --template react
cd my-react-app
npm install
npm run dev

// Next.js (Full-stack React)
npx create-next-app@latest my-next-app
cd my-next-app
npm run dev

// Project Structure
my-react-app/
ā”œā”€ā”€ public/
│   ā”œā”€ā”€ index.html
│   └── favicon.ico
ā”œā”€ā”€ src/
│   ā”œā”€ā”€ App.js
│   ā”œā”€ā”€ index.js
│   └── components/
ā”œā”€ā”€ package.json
└── README.md

// Basic App.js
import React from 'react';
import './App.css';

function App() {
  return (
    <div className="App">
      <header className="App-header">
        <h1>Welcome to React</h1>
        <p>Start building amazing applications!</p>
      </header>
    </div>
  );
}

export default App;
Swipe to see more code

Practice Exercise: React Setup

Code Example
// Exercise: Create a React Project
// 1. Set up a new React project
npx create-react-app todo-app
cd todo-app

// 2. Create a simple component
// src/components/TodoList.js
import React from 'react';

function TodoList() {
  const todos = [
    { id: 1, text: 'Learn React', completed: false },
    { id: 2, text: 'Build a project', completed: false },
    { id: 3, text: 'Deploy to production', completed: false }
  ];

  return (
    <div className="todo-list">
      <h2>My Todo List</h2>
      <ul>
        {todos.map(todo => (
          <li key={todo.id}>
            <input 
              type="checkbox" 
              checked={todo.completed}
              onChange={() => console.log('Toggle todo')}
            />
            <span style={{ 
              textDecoration: todo.completed ? 'line-through' : 'none' 
            }}>
              {todo.text}
            </span>
          </li>
        ))}
      </ul>
    </div>
  );
}

export default TodoList;

// 3. Update App.js
import React from 'react';
import TodoList from './components/TodoList';
import './App.css';

function App() {
  return (
    <div className="App">
      <header className="App-header">
        <h1>React Todo App</h1>
      </header>
      <main>
        <TodoList />
      </main>
    </div>
  );
}

export default App;

// 4. Add some basic styling
// src/App.css
.App {
  text-align: center;
  padding: 20px;
}

.todo-list {
  max-width: 500px;
  margin: 0 auto;
  text-align: left;
}

.todo-list ul {
  list-style: none;
  padding: 0;
}

.todo-list li {
  padding: 10px;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
  gap: 10px;
}

// 5. Run the application
npm start

// Challenge: Add a form to create new todos
// Challenge: Add functionality to delete todos
// Challenge: Add local storage to persist todos
Swipe to see more code

šŸŽÆ Practice Exercise

Test your understanding of this topic:

Additional Resources

šŸ“š Recommended Reading

  • •React Official Documentation
  • •Learning React by Alex Banks and Eve Porcello
  • •React Design Patterns and Best Practices by Michele Bertoli

🌐 Online Resources

  • •React Tutorial on reactjs.org
  • •React DevTools Documentation
  • •Create React App Documentation

Ready for the Next Module?

Continue your learning journey and master the next set of concepts.

Continue to Module 2