React

The most widely used UI library: JSX, components, props, state and events. Our recommended framework for your first job.

Intermediate · about 14 hours · difficulty 3/5

Learn first: Declarative UI and Component Thinking

React is a library for building user interfaces from components written as JavaScript functions that return JSX. It has the largest job market, ecosystem and community of any frontend framework, which is why we recommend it as your main framework.

The core API

  • JSX: HTML-like syntax that compiles to function calls. Use className, curly braces for expressions, and map to render lists (each item needs a stable key).
  • Components: function ProductCard({ product }) { return <article>...</article>; }. Names start with a capital letter.
  • Props: read-only inputs. Pass callbacks like onSelect for children to report events.
  • State with useState: const [count, setCount] = useState(0). Calling the setter schedules a re-render with the new value.
  • Events: onClick, onChange, onSubmit receive synthetic events similar to DOM events.
  • Conditional rendering: &&, ternaries, or early returns.
  • Controlled inputs: value plus onChange keep form fields in sync with state.

Getting started

Scaffold with Vite (npm create vite@latest, React plus TypeScript template) to learn the library itself, or with a framework such as Next.js later. Install React DevTools to inspect components and props.

Pitfalls

  • Mutating state (items.push(x)) instead of creating new arrays and objects.
  • Using the array index as key for lists that reorder.
  • Expecting state to update immediately after calling the setter; it applies on the next render.

Good enough to move on

You can build a multi-component app (a to-do list with filters, or a product catalogue with a cart) using props, state, events, lists and controlled inputs, typed with TypeScript.

Key concepts

  • JSX syntax and expressions
  • Function components and props
  • useState and updating state immutably
  • Handling events
  • Conditional rendering
  • Rendering lists and keys
  • Controlled form inputs
  • Children and composition
  • React DevTools
  • React with TypeScript

Other options for this step

  • Vue: A progressive framework with single-file components and fine-grained reactivity; approachable and popular in Asia and Europe.
  • Angular: A batteries-included framework from Google with TypeScript, dependency injection and signals; common in enterprises.
  • Svelte: A compiler-based framework with runes for reactivity and very little boilerplate; small bundles and a joyful developer experience.

Mini project

Build a product catalogue with search, category filters and a cart sidebar in React plus TypeScript, with state for the cart lifted to the top-level component.

Check yourself

Why does `cart.push(item); setCart(cart)` fail to re-render, and what should you write instead?

Free resources