Builder15 min readBadge: Component Builder

React basics: components, props and state

Read and fix the React code AI builders write: components, props, state, lists with keys, events, effects, and the errors you'll see most.

Components: the building blocks

A React app is a tree of components. A component is a function that returns what to show, written in JSX: HTML-like tags inside JavaScript. For example, function Greeting() { return <h1>Hello!</h1> } is used on a page as <Greeting />. Component names start with a capital letter.

Lovable, v0 and Bolt all write React, so most AI-built apps you open are folders of components: a Header, a TaskList, a SignUpForm. Reading an app starts with finding the component for the part of the screen you care about.

Props: inputs from the parent

Props pass data into a component, like arguments to a function. <Greeting name="Sam" /> sends a name, and function Greeting({ name }) { return <h1>Hello, {name}!</h1> } shows it. Curly braces put a JavaScript value into the JSX.

Props flow down from parent to child and are read-only: a component shouldn't change its own props. If a child needs to change something, the parent passes it a function to call, like onDelete.

State: the component's memory

A plain variable resets every time the component runs again. State remembers. const [count, setCount] = useState(0) gives you the current value and a setter. Calling setCount(count + 1) stores the new value and tells React to draw the component again, so the screen always matches the data.

Never change state directly. count++ or items.push(newItem) changes the old value without telling React, so the screen doesn't update. Always call the setter with a new value, for example setItems([...items, newItem]).

Lists, events and effects

  • Lists: items.map((item) => <li key={item.id}>{item.name}</li>). Each item needs a key that is unique and stable, usually an id from your data, so React can tell items apart. Don't use the array index when items can be added, removed or reordered, and never a random number.
  • Events: onClick={() => setOpen(true)} passes a function for React to call later. onClick={setOpen(true)} calls it straight away while drawing the screen, which loops.
  • Showing things conditionally: {isLoading ? <p>Loading…</p> : <TaskList />}, or {error && <p>{error}</p>}.
  • Effects: useEffect runs code after the screen updates, to keep in sync with things outside React such as a timer or a subscription. Wrong dependencies cause stale data or endless loops, and many things don't need an effect at all: work out values while rendering instead.

Errors you'll meet

  • "Each child in a list should have a unique key prop": add key={item.id} to the outer element inside the .map.
  • "Too many re-renders": something sets state while drawing, often onClick={setX(…)} instead of onClick={() => setX(…)}.
  • "Objects are not valid as a React child": you tried to show a whole object. Show one field, like {user.name}.
  • "Cannot read properties of undefined": the data hasn't arrived yet. Show a loading state or read it safely with user?.name.
  • "Hydration failed" in Next.js: the server and the browser drew different things, often the time, a random number or something from localStorage.

Key terms

React
The most popular JavaScript library for building interfaces from components.
Component
A reusable piece of interface, in React a function that returns what to show.
Props
The inputs passed into a React component.
State
Data a component or app remembers and updates, like what's in a cart.
JSX
HTML-like tags written inside JavaScript, which React turns into elements on the page.
Hook (React)
A React function whose name starts with use, like useState or useEffect, that adds a feature to a component.
useEffect
A React hook that runs code after the screen updates, to stay in sync with things outside React like timers.
Key (React lists)
A unique, stable id on each item in a list, so React can tell the items apart between renders.
DOM (Document Object Model)
The browser's live tree of a page's elements, which JavaScript can read and change.
Next.js
A React framework for pages, server code and fast loading, made by Vercel.
See the full glossary

Try it

Build and break a tiny to-do list

  1. Ask your AI builder for a React to-do list component with an input, an Add button and a list, using useState.
  2. Find the useState line and say out loud what the state variable and its setter are called.
  3. Find the .map and check each item has a stable key from an id, not the index or a random number.
  4. Add a 'done' checkbox to each item, then ask the AI to explain how it updates state without changing the old array.
  5. Break it on purpose: remove the key, open the browser Console and read the warning. Put it back.

Ask an AI tutor about this guide

Copy a prompt into ChatGPT, Claude or Gemini to go deeper. Check what it tells you against the guide.

Study with an AI tutor: copy this whole guide with tutoring instructions, then paste it into your AI assistant.
  • Explain it like I'm 12
  • Quiz me (5 questions, one at a time)
  • Show me a real example for my situation
  • What do beginners get wrong?

Knowledge check

Five questions. Get 4 right to earn the Component Builder badge. You can retake it as often as you like.

Question 1 of 5

What is a React component?

Finished the How software works guides? Take the How software works track test for ten mixed questions.

My notes

Write what clicked, what confused you, and what you want to try. Saved in this browser only.

Learn it live

Digital Builders University runs small live workshops where you build something real with an instructor beside you, starting with Vibe Coding 101.

See workshops

Practise it

Last reviewed November 25, 2026. AI tools change fast; check each tool’s own site for current features, plans and prices.