React.js Tutorials and Examples
Learn React components, JSX, events and state, then add TypeScript for typed props and data. Start with a small progress tracker and continue through the lessons below.
6 tutorials · Choose a topic below to open the full article.
Start here
TypeScript for React
Suggested learning sequence
- Components, JSX and props
- Events, state and conditional rendering
- Forms and API integration
Begin with the tutorial above, then practice the concepts in this sequence.
React components for beginners: build a reading list with JSX and props
A library wants two book cards. Both show a title and the number of copies available. Write the layout once in a component called BookCard. Give each copy of the component its own data through props.
App (reading list) ├── BookCard → River Walk, 3 copies └── BookCard → Night Train, 1 copy
Try it in App.jsx
Open a React starter project that supports JSX. Replace the contents of src/App.jsx with the example below and open the running app.
function BookCard({ title, copies }) {
return (
<article className="book">
<h2>{title}</h2>
<p>{copies} {copies === 1 ? 'copy' : 'copies'} available</p>
</article>
);
}
export default function App() {
return (
<>
<h1>Reading list</h1>
<BookCard title="River Walk" copies={3} />
<BookCard title="Night Train" copies={1} />
</>
);
}You should see two titles. River Walk shows “3 copies available” and Night Train shows “1 copy available”. Change the first count to 1. Both cards now use the singular word because both use the same formatting rule.
How to read the JSX
The capital B tells React to use your BookCard function. Lowercase article names a browser element. Braces let JSX evaluate JavaScript. Quotes pass text, so copies={1} passes a number while copies="1" passes text. Only the number passes our strict equality check.
The empty pair <> and </> groups siblings without adding another element to the page. Close tags even when empty, as in <input />. Use className for a CSS class and htmlFor on a label to match an input’s id. Event names use camel case, as in onClick.
Recognize a class component in older projects
Some projects define the same card as a class. To try this version, import Component from React at the top of the file and replace only the BookCard function. App still passes the same two props.
import { Component } from 'react';
class BookCard extends Component {
render() {
const { title, copies } = this.props;
return <article><h2>{title}</h2>
<p>{copies} {copies === 1 ? 'copy' : 'copies'} available</p>
</article>;
}
}Practice: Add a third card with zero copies. Change BookCard so it displays “On loan” for zero. Check that the other two cards still show their counts.
More React lessons and practice
Choose a topic below to open its full lesson on DevStudyHub. Read the explanation, try the example in the stated environment, and compare your result before continuing.
React Foundations & Virtual DOM Architecture
- React Overview, Declarative UI, Component-Driven Paradigm & Virtual DOM Reconciliation
- Modern Tooling: Vite vs Create React App, Project Structure & Fast Refresh
- JSX Syntax Architecture: Expressions, Fragments (<>...</>), Attributes & camelCase
- React 18 Rendering Pipeline: Render vs Commit Phase, Batching & Fiber Tree
Components, Composition & Props
- Function Components, Modular Code Splitting & Pure Component Principles
- Passing Props, Object Destructuring, Default Values & Immutable Prop Contracts
- Component Composition with props.children & Flexible Container Patterns
- Conditional Rendering: Inline Logical &&, Ternaries, Early Returns & Guard Clauses
State Management with useState
- State Fundamentals with useState: Triggers, Re-renders & Initializer Functions
- State Immutability: Updating Complex Objects, Spread Operator & Nested State
- Managing Array State: map(), filter(), concat() vs In-Place Mutation Traps
- Functional State Updates (prev => prev + 1) & Automatic Batching in React 18
Lists, Keys & Event Handling
- Rendering Dynamic Lists with .map(), The Role of Stable Keys vs Index Antipattern
- Synthetic Event System: onClick, onChange, onSubmit & e.preventDefault()
- Passing Arguments to Event Handlers, Inline Arrow Callbacks & Function Currying
- Lifting State Up: Sharing State Between Sibling Components via Common Ancestors
Forms & Controlled Components
- Controlled Components: Binding value and onChange for Single Source of Truth
- Dynamic Multi-Input Form Handling using Computed Property Names ([name]: value)
- Uncontrolled Components with useRef & Native HTML5 FormData API
Side Effects with useEffect
- Side Effects with useEffect: Mount, Update, Unmount & Mental Model
- Mastering the Dependency Array: Empty [], Specific Dependencies & Stale Closures
- Effect Cleanups: Canceling Subscriptions, Timers & AbortController on Unmount
- Asynchronous Data Fetching in useEffect, Loading States & Race Conditions
DOM Access & Mutable References with useRef
- Direct DOM Manipulation with useRef: Focus Management, Scrolling & Measurements
- Persisting Mutable Variables Across Renders Without Re-rendering via useRef
- Forwarding Refs with forwardRef & Custom APIs with useImperativeHandle
Complex State with useReducer
- Managing Complex Multi-Field State with useReducer: Actions, Reducers & Dispatch
- Architectural Decision Matrix: When to Choose useReducer over useState
- Simplifying Nested Reducer Mutations with Immer or Immutable Helpers
Global State with Context API
- Eliminating Prop Drilling with createContext, Context.Provider & useContext
- Modular Custom Context Providers: Bundling State and Dispatch Handlers
- Context Performance: Preventing Unnecessary Consumer Re-renders with Split Contexts
Performance Optimization & Memoization
- Pure Component Memoization with React.memo & Shallow Prop Comparisons
- Stabilizing Function References with useCallback to Prevent Child Re-renders
- Caching Costly Computations with useMemo & Referential Identity Preservation
- Bundle Splitting with React.lazy() & Asynchronous Fallback UI with <Suspense>
Custom Hooks & Reusable Logic
- Authoring Custom Hooks: Rules of Hooks, 'use' Prefix & Logic Encapsulation
- Practical Custom Hooks: Building useFetch & useLocalStorage
- Advanced Custom Hooks: Building useDebounce & useWindowSize
React 18 Concurrency & Transitions
- React 18 Concurrency: Urgent vs Non-Urgent Updates with startTransition & useTransition
- Deferring High-Latency Value Computations with useDeferredValue
- Generating Unique Accessible Form Identifiers with useId Across SSR & Client
Error Handling & Portals
- Error Boundaries: Declarative Fault Tolerance & Component Fallbacks
- Portals: Rendering Modals, Tooltips & Escaping CSS Stacking Contexts
- React.StrictMode: Double Invocations, Detecting Side-Effects & Dev Warnings
Client-Side Routing & Navigation
- React Router: BrowserRouter, Routes, Route & NavLink Client Routing
- Dynamic Params, useNavigate & Nested Layouts with <Outlet />
React 19 Innovations & Production Architecture
- React 19 Actions: useActionState, Transitions & useOptimistic
- React 19 use() Hook: Reading Promises & Conditional Context
- Production Build, Vite Optimization & Security Checklist
Extra practice
Follow the ordered React learning path · Practice with coding games · Visit DevStudyHub
No comments:
Post a Comment
Please do not enter any spam link in the comment box.