›bobbyencoded_
/posts/newsletter/courses/about
/posts/newsletter/courses/about

The Decode

The week's AI & software news, decoded.

Subscribe →

// © 2026 BobbyEncoded Inc. — A Canadian corporation

← Back to Blog

React Learning Path

React Learning Path, Part 1: The Fundamentals

November 7, 2026 · 10 min read

React, Interview Prep, JavaScript, TypeScript, Frontend

If you want to learn React properly, or check that what you know still holds up in React 19, you want one path through it instead of ten tabs. This series is that path, in three parts:

  1. The fundamentals (this post): the things you should be able to explain without notes.
  2. How React works day to day: rendering, hooks in depth, effects, data, forms, testing.
  3. Advanced and React 19: reconciliation, concurrent rendering, Actions, the compiler, Server Components.

Each part keeps the code short, ends with questions to check yourself, with answers, and links to the longer posts I wrote in 2025 when you want depth. Examples are TypeScript, because that's what most React codebases use now.

What React is, in one sentence

React turns state into UI. You describe what the screen should look like for a given state, and React works out how to update the page when the state changes. That's what "declarative" means: you write the what, not the step-by-step how.

Three ideas carry the whole library:

  • Components: functions that return UI.
  • Props: inputs passed down from a parent.
  • State: data a component owns that can change over time. When it changes, React re-renders the component.

JSX

JSX looks like HTML inside JavaScript, but it compiles to plain function calls. With the modern JSX transform, <h1 className="title">Hi</h1> becomes roughly jsx("h1", { className: "title", children: "Hi" }). That's why it has a few differences from HTML:

function Welcome({ name, isAdmin }: { name: string; isAdmin: boolean }) {
  return (
    <>
      {/* Fragment: group elements without an extra <div> */}
      <h1 className="title">Hello, {name}</h1>   {/* className, not class */}
      {isAdmin && <span>Admin</span>}             {/* conditional rendering */}
      <p>{isAdmin ? "Full access" : "Read only"}</p>
    </>
  );
}

The rules worth remembering:

  • Curly braces hold expressions, not statements. {items.length} works; {if (x) ...} doesn't. Use && or a ternary.
  • One root element. Wrap siblings in a fragment <>...</>.
  • className and htmlFor, because class and for are reserved words in JavaScript.
  • Watch && with numbers. {count && <Badge />} renders a literal 0 when count is zero. Write {count > 0 && <Badge />}.

Components and props

A component is a function that takes props and returns JSX. Component names start with a capital letter, which is how React tells <Button> (your component) from <button> (an HTML element).

type ButtonProps = {
  label: string;
  variant?: "primary" | "secondary"; // optional, with a default below
  onClick: () => void;
};

function Button({ label, variant = "primary", onClick }: ButtonProps) {
  return (
    <button className={`btn btn-${variant}`} onClick={onClick}>
      {label}
    </button>
  );
}

function Card({ title, children }: { title: string; children: React.ReactNode }) {
  return (
    <section className="card">
      <h2>{title}</h2>
      {children} {/* whatever the parent put between <Card> and </Card> */}
    </section>
  );
}

Two rules worth knowing:

  • Props are read-only. A component must never change its own props. Data flows down through props; changes flow up through callbacks like onClick. This is "one-way data flow."
  • Components should be pure while rendering: same props and state in, same JSX out, no side effects in the function body. Side effects go in event handlers or effects.

children is how you build composable components like Card. It's the reason React rarely needs inheritance: you compose components instead of extending them.

State with useState

State is data that changes and should update the screen. useState gives you the current value and a setter.

import { useState } from "react";

function Counter() {
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>Clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>+1</button>
      {/* Functional update: use when the new value depends on the old one */}
      <button onClick={() => setCount((c) => c + 1)}>+1 (safe)</button>
    </div>
  );
}

What trips people up:

  • Setting state doesn't change the variable immediately. count is a snapshot for this render. Calling setCount(count + 1) three times in one click still adds 1, because all three read the same count. The functional form setCount(c => c + 1) adds 3, because each update gets the latest value.
  • Updates are batched. Since React 18, several state updates in the same event (or timeout, or promise) cause one re-render, not several.
  • Never mutate state. For objects and arrays, create new ones. React compares the old and new value by reference; if you mutate in place, it can't tell anything changed.
type Todo = { id: number; text: string; done: boolean };

function useTodos() {
  const [todos, setTodos] = useState<Todo[]>([]);

  const add = (text: string) =>
    setTodos((prev) => [...prev, { id: Date.now(), text, done: false }]); // new array

  const toggle = (id: number) =>
    setTodos((prev) => prev.map((t) => (t.id === id ? { ...t, done: !t.done } : t))); // new objects

  return { todos, add, toggle };
}

(That's also a custom hook: a function starting with use that calls other hooks. Part 2 covers them properly.)

Events

React handlers are camelCase props that take a function, not a string:

function SearchBox({ onSearch }: { onSearch: (q: string) => void }) {
  const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
    e.preventDefault(); // stop the browser's full-page form submit
    const data = new FormData(e.currentTarget);
    onSearch(String(data.get("q") ?? ""));
  };

  return (
    <form onSubmit={handleSubmit}>
      <input name="q" />
      <button type="submit">Search</button>
    </form>
  );
}

The classic bug: onClick={handleClick()} calls the function during render. Pass the function itself (onClick={handleClick}), or wrap it when you need arguments (onClick={() => remove(id)}).

React wraps native events in a SyntheticEvent with the same interface across browsers, and attaches listeners at the root of your app rather than on every element.

Lists and keys

Render lists with map, and give each item a stable key:

function TodoList({ todos }: { todos: Todo[] }) {
  if (todos.length === 0) return <p>Nothing to do.</p>; // early return for empty state

  return (
    <ul>
      {todos.map((todo) => (
        <li key={todo.id}>{todo.text}</li> // key: stable and unique among siblings
      ))}
    </ul>
  );
}

Keys tell React which item is which between renders. With a stable id, React can move, add or remove the right element. If you use the array index and the list gets reordered or an item is inserted at the top, React matches the wrong elements: inputs keep the wrong text, and component state ends up attached to the wrong row. Use the index only for static lists that never reorder.

Controlled inputs

A controlled input gets its value from state, and every keystroke updates the state. React is the single source of truth:

function NameForm() {
  const [name, setName] = useState("");

  return (
    <label>
      Name
      <input value={name} onChange={(e) => setName(e.target.value)} />
      {name.length > 0 && name.length < 2 && <span>Too short</span>}
    </label>
  );
}

An uncontrolled input keeps its own value in the DOM, and you read it when you need it (with a ref, or from FormData on submit, like SearchBox above). Controlled is easier to validate as the user types; uncontrolled is simpler and faster for big forms. Libraries like React Hook Form lean uncontrolled for that reason.

A first look at useEffect

Rendering must be pure, so where do side effects go: subscriptions, timers, talking to a non-React widget? Into useEffect, which runs after React has updated the screen.

import { useEffect, useState } from "react";

function OnlineStatus() {
  const [online, setOnline] = useState(navigator.onLine);

  useEffect(() => {
    const update = () => setOnline(navigator.onLine);
    window.addEventListener("online", update);
    window.addEventListener("offline", update);
    return () => {
      // cleanup: runs before the effect re-runs and when the component unmounts
      window.removeEventListener("online", update);
      window.removeEventListener("offline", update);
    };
  }, []); // dependency array: [] = set up once after the first render

  return <p>{online ? "Online" : "Offline"}</p>;
}

The dependency array decides when the effect runs again: no array means after every render, [] means once, and [userId] means whenever userId changes. The cleanup function undoes whatever the effect set up.

One thing that surprises everyone: in development with <StrictMode>, React mounts, unmounts and re-mounts each component once, so your effect runs, cleans up, and runs again. That's deliberate. It flushes out effects that forget to clean up. It doesn't happen in production.

The best mental model, from the React docs: an effect synchronizes your component with something outside React. If there's no outside system involved, you probably don't need an effect. Part 2 is mostly about that sentence.

Check yourself: questions and answers

1. What is the virtual DOM?

A lightweight description of the UI as plain objects. When state changes, React renders a new description, compares it with the previous one (reconciliation), and applies only the differences to the real DOM. The point isn't that the virtual DOM is "fast"; it's that you write declarative code and React works out the minimal updates.

2. What's the difference between props and state?

Props are inputs from the parent and are read-only inside the component. State is owned by the component and changes over time through its setter. Changing either causes a re-render.

3. Why shouldn't you mutate state directly?

React decides whether something changed by comparing references. Mutating an object or array keeps the same reference, so React may skip the update, and it breaks features that rely on old values staying intact.

4. Why does calling setCount(count + 1) three times only add one?

count is a snapshot of the value for this render, so all three calls compute the same number. Use the functional form setCount(c => c + 1) when the new value depends on the previous one.

5. Why do lists need keys, and why not the index?

Keys identify items between renders so React can keep the right DOM nodes and state with the right item. Index keys break when the list is reordered, filtered or has items inserted, because the same index now points to a different item.

6. Controlled vs uncontrolled components?

Controlled: the value lives in React state and updates on every change, which suits live validation. Uncontrolled: the DOM holds the value and you read it when needed, which is simpler and cheaper for large forms.

7. What does the dependency array in useEffect do?

It lists the values the effect reads. React re-runs the effect when any of them change. Empty means run once after mount; omitted means run after every render. Leaving out a value you use causes stale-value bugs.

8. What is a fragment, and why use one?

<>...</> groups elements without adding a DOM node, so you can return siblings from a component without wrapping them in an extra <div>.

9. What does "one-way data flow" mean?

Data passes down from parent to child through props. A child can't change the parent's data directly; it calls a callback the parent passed in, and the parent updates its own state.

10. Why does React need component names to start with a capital letter?

JSX uses the case to decide: lowercase tags become HTML elements ("div"), capitalized ones are treated as variables referring to your components.

Go deeper

These are the longer posts from my 2025 React series that this part draws on:

  • React Foundations: JSX, Components, and Props, with more on JSX rules, props and lists
  • React State and Hooks: The Complete Guide, with useState, useEffect, useRef and custom hooks in depth
  • React Forms and Validation, for controlled vs uncontrolled forms at scale
  • TypeScript with React, on typing props, events and hooks

Next: Part 2, how React works day to day.

Further reading

  • React docs, Describing the UI and Adding Interactivity
  • React docs, Synchronizing with Effects
← Previous

React Learning Path, Part 2: How React Works Day to Day

Next →

Siri and Android Both Want Your App to Be an Agent Tool Now

Thoughts on this?

Tell me on X: @bobbyencoded · Share this post on X

Want more like this? Subscribe to The Decode, a weekly email on the AI and developer news worth your time.