React

React is a JavaScript library for building user interfaces from reusable components. You describe what the UI should look like for a given state, and React efficiently updates the DOM when that state changes — a declarative model instead of manually patching the page.

What it solves: before React, updating complex UIs meant manually tracking which parts of the page changed when data updated — bug-prone, slow, and hard to maintain. React lets you describe what the UI should be for any state and figures out how to update the DOM.

Where it fits: React owns the "view" layer. Created at Facebook and open-sourced in 2013, it pairs with routing (React Router), state (Zustand, Redux), data fetching (TanStack Query), and meta-frameworks (Next.js, Remix) to build complete apps. Its component model shaped Vue, Svelte, and others.

TL;DR

Quick Example

A function component with local state via the useState hook:

Core Concepts

Key terms

Mental models

A component is a function from data to UI: given props and state, it returns a description of the screen; when data changes, it runs again and returns a new description. The Virtual DOM is a draft — React writes changes to the draft, compares it to the live page, and updates only what differs.

What beginners misunderstand

How React Works

A scheduler prioritizes and batches updates so the UI stays responsive. Complexity tends to arise around where state lives, effect dependency arrays (stale closures / infinite loops), unnecessary re-renders, and the server/client boundary.

Component Types

Hooks

Hooks let function components use React features:

⚠️ Don't reach for useEffect to compute values from props/state — derive them during render. Effects are for syncing with the outside world.

Best Practices

Tooling & Ecosystem

React itself is MIT-licensed and maintained by Meta; the ecosystem is overwhelmingly open-source.

Performance & Scaling

Common bottlenecks and the levers that address them:

Comparison to Other Frameworks

React wins on ecosystem maturity, hiring pool, and flexibility. Vue wins for a gentler curve and built-in defaults; Svelte for performance and tiny bundles; Angular when teams want an enforced architecture. See Vue, Svelte, Angular.

Common Mistakes

Mutating state directly

Missing keys in lists

Overusing useEffect

FAQ

Is React a framework or a library?

A library — it only handles the view. You add routing, state management, and data fetching yourself, or adopt a meta-framework like Next.js that bundles those choices.

Do I need Redux?

Usually not. Local state plus Context covers many apps; reach for Zustand, Jotai, or Redux Toolkit only when shared, frequently-updated state gets unwieldy. See State Management.

Class or function components?

Write new code with function components and hooks. Class components still work and aren't removed, but hooks are the modern standard for state and logic reuse.

What are React Server Components?

Components that render on the server with zero client JavaScript, enabling direct data access and smaller bundles. They can't use hooks or browser APIs. See React Server Components.

Why does my component re-render so often?

Usually because state lives too high or a parent re-renders and recreates props. Move state down, memoize stable callbacks/values, and split components so unrelated updates don't cascade.

When should I not use React?

For static, low-interactivity sites (plain HTML or a static generator may be simpler) or when SEO is critical without SSR/SSG. For maximum runtime performance, Svelte or vanilla JS can be lighter.

Related Topics

References