Chapter 1 of 20 · React for Beginners — Complete Free Tutorial

Introduction to React

Welcome to the React for Beginners series on Scriptly. Across twenty hands-on chapters you will go from an empty folder to a deployed single-page application. This first chapter answers three questions: what React actually is, why developers reach for it instead of plain DOM code, and how the pieces you are about to learn — components, props, state and JSX — fit together.

What React is

React is a JavaScript library for building user interfaces out of small, reusable pieces called components. It was open-sourced by Facebook in 2013 and is now maintained by Meta together with a large open-source community. React deliberately covers only the view layer: it does not dictate how you fetch data, style pages or handle URLs, so you pair it with tools such as Vite and React Router as your project grows.

  • Declarative — you describe what the screen should look like for a given set of data, and React works out the DOM updates.
  • Component-based — every button, form and page is a function you can reuse, test and reason about in isolation.
  • Learn once, use widely — the same mental model powers web apps, React Native mobile apps and many component libraries.

Imperative vs declarative UI

In plain JavaScript you tell the browser how to change the page, step by step. If you have written code with addEventListener and textContent in the DOM chapters, you know how quickly the instructions pile up:

let count = 0;
const label = document.querySelector('#label');
const button = document.querySelector('#button');

button.addEventListener('click', () => {
  count = count + 1;
  label.textContent = `${count} clicks`;
});

Expected output:

0 clicks
1 clicks
2 clicks   (after each click — you wrote every DOM instruction yourself)

React flips the model: you render the result and let React apply the differences.

ApproachYou writeRisk when data changes
Imperative (plain DOM)Every step: find node, update nodeMissed updates, stale UI, tangled code
Declarative (React)The UI for the current dataReact keeps the DOM in sync for you

Components: UI built from functions

A React component is a plain function that returns a description of UI. The syntax below looks like HTML but is JSX, the topic of the next-but-one chapter — for now notice that logic and markup live together:

function Greeting({ name }) {
  const hour = new Date().getHours();
  const mood = hour < 12 ? 'Good morning' : 'Good afternoon';

  return (
    <h1 className="greeting">
      {mood}, {name}!
    </h1>
  );
}

Expected output: for name = "Ada" the page shows a single heading — Good afternoon, Ada! — recomputed every time the component runs. One function, one piece of screen.

Rendering and the virtual DOM

When React renders a component it simply calls the function and captures what it returned as a lightweight description. React keeps two copies of that description — the previous one and the new one — compares them, and applies only the real differences to the browser's DOM. This comparison layer is often called the virtual DOM, and the process of comparing and applying is reconciliation.

  1. Something changes — a click handler, fetched data, a timer.
  2. React calls your component function again with the new data.
  3. React diffs the old and new descriptions and updates only what changed.

That is why updating a counter ten times does not rebuild the page ten times: only the text node holding the number is touched.

Props, state and shared vocabulary

React code leans on a small vocabulary. Learning it now makes every later chapter easier to read:

TermMeaningWhere you meet it
ComponentFunction returning a UI descriptionChapter 3
PropsRead-only inputs a parent passes downChapter 5
StatePrivate data that changes over timeChapter 6
HookFunction like useState that adds state or effectsChapters 6 and 12
RenderCalling components to produce the current UIEvery chapter

Data flows in one direction: parent to child through props, events back up through callback functions. This one-way data flow is what keeps large applications predictable.

The modern React landscape

This series is written for the React 18/19 era and uses function components and hooks only. A few names you will hear, with honest context:

  • Vite — the build tool and dev server used throughout; it starts instantly and replaces the older Create React App, which is now effectively retired.
  • Hooks — useState, useEffect and friends bring state and lifecycle to functions.
  • Class components — the pre-2019 style with this and lifecycle methods. You only need to recognise them when reading old code; this course does not use them.
  • React 19 — the current stable release, adding quality-of-life features while keeping everything you learn here fully valid.

Common mistakes

  • Expecting React to replace JavaScript — React is JavaScript; functions, arrays and destructuring do all the heavy lifting.
  • Trying to memorise the API first — the mental model (declarative UI, one-way data flow) matters more than any single hook signature.
  • Assuming rendering means the whole page redraws — React diffs descriptions and touches only changed DOM nodes.
  • Starting with a class-based tutorial — old articles rely on this.state and lifecycle methods that modern code no longer needs.
  • Skipping the DOM basics — events, elements and the difference between HTML and DOM still matter; React sits on top of them.

Practice checklist

  1. Explain the difference between imperative and declarative UI in one sentence, using the counter example.
  2. Write down the five vocabulary terms from the table from memory, then check them.
  3. Read the intro paragraph of each remaining chapter title in the sidebar and note which concepts are completely new to you.
  4. Skim Introduction to JavaScript if functions or array methods feel rusty — you will use them constantly.

You now know what React solves. Next, install the toolchain that makes development instant — Setting Up React with Vite.

Quiz: Introduction to React

5 questions · 70% to pass

Frequently Asked Questions

React is a JavaScript library for building user interfaces from reusable components. It manages how your UI updates when data changes, so you describe what the screen should look like and React performs the efficient DOM updates. It is one of the most in-demand frontend skills and powers products from Netflix to Instagram, which makes it an excellent next step after core JavaScript.

You should be comfortable with functions, arrays and objects (map, filter, spread), destructuring, modules and basic async/await. React itself is written in plain JavaScript — JSX is a syntax layer on top. If any of those feel shaky, revisit the JavaScript fundamentals first and this series will go much faster.

React is a library focused only on the UI layer — you choose your own router, data layer and tooling. Angular is a full framework that ships routing, forms, HTTP client and testing conventions as one opinionated package. React's flexibility and huge ecosystem make it the common choice for teams that want to compose their own stack.

A component is a reusable function that returns UI. It receives input through props, keeps private data in state, and can render other components. Pages are composed by nesting small components (navbar, card list, footer) instead of one giant file, which keeps code testable and easy to change.

JSX is a syntax extension that looks like HTML but compiles to React's create() calls — it is a description of UI, not markup the browser parses. Small differences matter: class becomes className, style takes an object, and you embed JavaScript expressions inside curly braces. Once compiled, React turns that description into real DOM nodes.

Props are inputs passed from a parent — they are read-only inside the child, like function arguments. State is private, mutable data owned by a component; updating it triggers a re-render. The rule of thumb: values that come from outside the component are props; values that change over the component's lifetime are state.

Rendering means calling your component function to produce a description of the UI for the current state and props. It does not always mean DOM work — React compares the new description with the previous one (reconciliation) and applies only the differences to the real DOM. This is why updating state 100 times does not mean 100 full page rebuilds.

An effect runs after the component has committed to the screen — after render, not during it. You list dependencies in an array, and React re-runs the effect only when one of them changes. If the effect returns a cleanup function, React runs it before the next re-run and on unmount, which is where you cancel timers, abort fetches and remove listeners.

Use Vite. Create React App is effectively in maintenance mode, while Vite starts instantly (native ES modules) and builds fast, and it is the default choice for new React projects. This series uses Vite for every example — you only need Node.js installed to follow along.

React apps compile to static files (HTML, CSS and JavaScript), so any static host works: Netlify, Vercel, GitHub Pages or Cloudflare Pages. Run the production build, upload the dist folder, and configure a single-page-application fallback so unknown paths load index.html — routing chapters explain why that fallback is required.