React Foundations

React is a UI library focused on component composition and predictable rendering from state.

What React solves

Before declarative UI libraries, updating a complex screen meant manually querying DOM nodes, tracking which elements were stale, and risking out-of-sync UI state. React replaces imperative DOM mutations with a declarative model:

  • Complex interactive UIs: Describe what the screen should look like for any given state, and let React reconcile the DOM.
  • Reusable UI components: Encapsulate markup, behavior, and local state into composable building blocks.
  • Clear one-way data flow: Data flows top-down via props while events flow bottom-up via callbacks, making bugs easier to trace.

Mental model

Think of every React component as a pure function of its inputs: UI = f(props, state). When state updates through a setter, React re-runs your component function to produce a fresh description of the UI rather than mutating DOM elements by hand.

JSX principle

JSX looks like HTML inside JavaScript, but Babel/Vite compiles it into standard JavaScript function calls that return lightweight element objects. Embedding JavaScript expressions inside curly braces lets you render dynamic values directly alongside markup:

function Welcome({ user = "Developer" }) {
  // Compiled to React element objects, not raw HTML strings
  return <h1>Hello, {user}</h1>;
}

Virtual DOM and diffing

Instead of tearing down and rebuilding the entire browser DOM on every state change, React compares the newly returned element tree against the previous tree (reconciliation) and commits only the minimal set of DOM updates needed.

Professional tips

Keep these habits in mind as you start building React interfaces:

  1. Think in components and state boundaries before writing CSS or layout markup.
  2. Avoid premature optimization; write clear, pure render functions first and profile before adding memoization.
  3. Keep data flow explicit—avoid hidden global mutations outside React's state model.

Practice

Sketch a component tree for a dashboard page (header, filter bar, data table, status badge) and label which component owns each piece of state before writing code.