Skip to Content
React in a Week
Day 1 · JS → first component

Day 1: JavaScript to your first component

Learn the modern JavaScript React relies on, then write JSX and build your first components.

Today has two halves. In the morning you learn the JavaScript that React code uses on nearly every line: arrow functions, destructuring, spread, map and filter, and modules. In the afternoon you put it to work: you learn what React is, how JSX works, and you write your first components.

Why start with JavaScript? Because most "React problems" beginners hit are really JavaScript problems in disguise. A component is a JavaScript function, and once the JavaScript feels familiar, React becomes much easier to follow. If you already know modern JavaScript well, try the challenge at the end of each JS lesson. If you solve it easily, move on.

Time plan

Plan for about five hours, including breaks.

LessonTimeWhat you'll do
Variables, functions and conditions40 minconst, arrow functions, template literals, the ternary and &&
Objects, arrays, destructuring and spread40 minModel a book as an object, unpack it, and copy it safely
Array methods35 minTransform and search a reading list with map, filter and find
Modules25 minSplit code into files with import and export
What is React?25 minCompare step-by-step DOM code with React's declarative style
JSX45 minLearn the rules of JSX and use curly braces
Your first component40 minDefine, nest and import components
Project checkpoint30 minBuild the BookCard component in your own project

What you'll build today

By the end of today, your Reading List app shows a heading and two book cards, built from a BookCard component that lives in its own file.

Both cards show the same book, because BookCard has its title and author written directly inside it. That is on purpose. Tomorrow you will learn props, which let each card show a different book.

Today's lessons

Project checkpoint · Day 1 · Reading List

Time to bring today's ideas into your own project. Open the reading-list folder from Day 0 in VS Code, and start the dev server with npm run dev if it is not already running.

Create the BookCard component

In the src folder, create a new file called BookCard.jsx:

src/BookCard.jsx
export function BookCard() {
  return (
    <article className="book-card">
      <h2>The Hobbit</h2>
      <p>by J.R.R. Tolkien</p>
    </article>
  );
}

The className does nothing yet. You will add the styles for it on Day 2.

Use it in App

Replace the contents of src/App.jsx with:

src/App.jsx
import { BookCard } from './BookCard.jsx';

export default function App() {
  return (
    <>
      <h1>My Reading List</h1>
      <BookCard />
      <BookCard />
    </>
  );
}

App now returns three elements, so they are wrapped in a Fragment. BookCard is a named export, so it is imported with curly braces. The rest of the course uses named exports for components; only App stays a default export.

Check it in the browser

Save both files. Your browser should show the heading and two identical cards. Open the Components tab in React DevTools: you should see App with two BookCard children.

Stretch goal: add a Header component in src/Header.jsx that contains the <h1>, and use <Header /> in App instead.

If something goes wrong, compare your code with the sandbox below. In the sandbox the files are named .js; in your project they are .jsx, and the code inside is the same.

Live code· Reading List, end of Day 1

Day 1 progress

0/8

On this page