TechDojoPilot Cohort Week 2 · Day 8

Pilot CohortPhase 1Week 2Day 8

React and TypeScript Basics, and Setting Up Next.js

Your day, about 6 hours

  1. Learn2 hSections 4 to 9
  2. Build2 hSection 10
  3. Flex1 hJournals, then catch-up, section 11
  4. Stand-up1 hLive, 9 pm WAT
01

Daily theme and context

On Days 6 and 7 you built screens by hand: take an array, create elements, put them on the page, update them when something changes. That works, but it gets messy fast. React is a library that does this for you: you describe what the screen should look like for the current data, and React keeps the page in step. TypeScript adds types to JavaScript, so mistakes like a misspelt property are caught before the code runs. Next.js is a framework built on React that gives the app its structure (pages, layouts, routing) and makes it easy to put live, which you'll do on Friday.

Today you set up the Tracker as a Next.js app and rebuild its first pieces as React components.

This is also the first day your AI coding assistant may write code for you. Section 8 explains the rule that comes with it.

This is Week 2 of the Pilot Cohort's six-week Learn phase ("Frontend"), Day 8 of 30 learning days. Day 8 starts at the Wednesday (25 Nov) 9 pm class; its work goes into Quest 2, due by Sunday 29 Nov, 11:59 pm WAT. It has four blocks, about 6 hours, done whenever suits you except the stand-up: Learn (2 hours, covered in full below), Build (2 hours, section 10: the Learner Project Tracker), Flex (1 hour: your three journals first, then catch-up, then the optional open-source practice in section 11), and the live stand-up at 9 pm WAT (1 hour).

02

Learning objectives

By the end of today, the learner should be able to:

  1. Explain what React does, in plain words: the screen is built from components, from data.
  2. Write a function component that returns JSX, and use it more than once.
  3. Pass data into a component through props, and type those props with TypeScript.
  4. Explain what TypeScript adds to JavaScript and read a basic TypeScript error.
  5. Create a Next.js app with TypeScript, run it locally, and organise your own files in it: pages and layout in app, components in components, data in lib.
  6. Use an AI assistant to write code, then explain every line of what you keep, and check any command it wants to run before allowing it.
03

Prerequisite knowledge

Day 6's objects, arrays and map; Day 7's events and forms; the Git branch and pull-request loop from Day 5.

  • Creating a Next.js app is a large download. Create one app today, the Tracker (section 10), and do the exercise inside it, so you only download it once.
  • On Windows, if PowerShell says "running scripts is disabled on this system" when you type npm or npx, use Git Bash (installed with Git in Week 1) or the Command Prompt instead.
  • If something in the setup fails, copy the exact error into the cohort group. Setup errors are normal and usually quick to fix with the message in front of someone.
  1. Go to opencode.ai, click Download for Windows (or the version for your computer), and install OpenCode Desktop. Only download it from opencode.ai.
  2. After you've created the Tracker app (section 10), open the Tracker folder in OpenCode Desktop.
  3. Choose DeepSeek V4.1 Flash Free from the model list. Its provider keeps no copy of what you send and doesn't use it for training. If it's unavailable, choose Hy4 flash Free, which has the same policy. Don't use the free models whose providers collect your prompts to improve their models, such as Big Pickle.
  4. Check it works: ask it to "explain what app/page.tsx does, without changing anything". It should describe your file.

Get OpenCode DesktopOpens opencode.ai in a new tab.

When OpenCode asks to edit a file or run a command, read the request before you allow it (rule 5 in section 4). Free models are free for a limited time and can be slow when they're busy. If one stops responding, choose another from the model list and note it in your AI-use journal.

  • Plan before you prompt. Know exactly what you want, and ask for it in one clear message.
  • Ask for one small thing at a time (one component, one fix), never "build the whole page".
  • Start a new session for each new task. A long session sends its whole history with every message, so each message costs more than the last.
  • Write first versions by hand (rule 1 in section 4), and use your free chat assistant for explanations and questions.
  • If you hit the limit, switch to Hy4 flash Free, or carry on by hand until it resets the next day.
04

TechDojo core lesson

35 minutes

The idea behind React

On Day 7, adding a learner meant updating your array and remembering to update the page. Forget the second step and the screen is wrong. React removes that second step: you write a function that says "given this data, the screen looks like this", and React updates the page whenever the data changes. The screen is always a result of the data.

Days 6 and 7By hand
  • Change the array
  • Remember to redraw the page
  • Forget, and the screen is wrong
React
From todayWith React
  • Change the data
  • React redraws what depends on it
  • The screen always matches the data

Components and JSX

A component is a function that returns a piece of the screen. It is written in JSX, which looks like HTML inside JavaScript:

function LearnerCard() {
  return (
    <div className="card">
      <h2>Ada</h2>
      <p>Attendance: 90%</p>
    </div>
  );
}

Component names start with a capital letter. You use a component like an HTML tag: <LearnerCard />. Three JSX rules catch everyone at first: use className instead of class; a component returns one outer element (wrap siblings in <>…</> if needed); and anything inside curly braces is JavaScript, so <p>{learner.name}</p> shows the value.

Props: passing data in

A card that always says "Ada" isn't useful. Props are the inputs to a component, like a function's parameters:

type LearnerCardProps = { name: string; rate: number };

function LearnerCard({ name, rate }: LearnerCardProps) {
  return (
    <div className="card">
      <h2>{name}</h2>
      <p>Attendance: {rate}%</p>
    </div>
  );
}

<LearnerCard name="Ada" rate={90} />

A component never changes its own props; they come from its parent.

  1. 1Parentapp/page.tsx has the learner data
  2. 2Propsname="Ada" rate={90}
  3. 3LearnerCardReads its props, never changes them
  4. 4The screenOne card for that learner

Lists of components

Day 6's map becomes the way to show lists:

<ul>
  {learners.map((l) => (
    <li key={l.id}><LearnerCard name={l.name} rate={attendanceRate(l)} /></li>
  ))}
</ul>

Each item in a list needs a key that is unique and stable (an id, not its position), so React can tell items apart when the list changes.

TypeScript, kept small

TypeScript lets you state the shape of your data, and the editor checks it as you type. This week you only need two things:

  • A type for your data: type Learner = { id: number; name: string; attendance: number; sessions: number };
  • Typed props, as in LearnerCardProps above.

Functions get types too: what goes in, and what comes out.

function attendanceRate(learner: Learner): number {
  if (learner.sessions === 0) return 0;
  return Math.round((learner.attendance / learner.sessions) * 100);
}

learner: Learner says the input must be a learner; : number after the brackets says the result is a number.

Now if you write learner.nmae, or pass rate="90" (text) where a number is expected, the editor underlines it in red before you even run the page. Read the message: it says what was expected and what you gave. TypeScript errors are not something to silence; they are bugs caught early.

Next.js: the structure around React

A new Next.js app has a folder called app. Inside it:

  • app/page.tsx is the home page (what you see at /);
  • app/layout.tsx wraps every page: the place for the navigation and footer that every screen shares;
  • app/globals.css holds global styles.

Run the app with npm run dev and open localhost. Edit page.tsx, save, and the browser updates on its own. Friday covers adding more pages and putting the app live.

Where your own files go

Create two folders yourself, next to app:

tracker/
  app/
    layout.tsx    nav and footer
    page.tsx      the home page
    globals.css
  components/
    LearnerCard.tsx
    StatusBadge.tsx
  lib/
    learners.ts   Learner type and data

Put one component in each file, and export it with export default. Import it with @/, a shortcut that means "from the project's top folder", so the path is the same from any file:

// components/LearnerCard.tsx
export default function LearnerCard({ name, rate }: LearnerCardProps) { … }

// app/page.tsx
import LearnerCard from "@/components/LearnerCard";
import { learners, attendanceRate } from "@/lib/learners";

export default marks the one main thing a file exports, so its import has no curly braces. Named exports, like Day 6's, keep them.

Using an AI assistant to write code: the rule

From today your AI coding assistant may write code. The programme rule stays the same: if you can't explain a line, it doesn't ship. In practice:

  1. Write the first version of something yourself where you can, so you know what good looks like.
  2. When AI writes code, read every line before you keep it. Look up anything you don't understand, or ask the assistant to explain it.
  3. Run it and check it against what you actually need (your acceptance criteria), not against whether it looks finished.
  4. Record it in your AI-use journal: what it wrote, what you changed, what you rejected, and why.
  5. A coding assistant can also create files and run commands. Read every command before you allow it, and say no to anything you don't understand (ask it to explain first). Never paste passwords, keys or anyone's personal details into a prompt.

Reviewers will point at lines at random at Gate 2 and ask what they do.

  • ReadEvery line before you keep it, and every command before you allow it.
  • CheckRun it against your acceptance criteria, not how finished it looks.
  • ChangeAnything you'd do differently, or anything you can't explain.
  • RecordIn your AI-use journal: kept, changed, rejected, and why.
If you can't explain a line, it doesn't ship.Reviewers point at lines at random at Gate 2.
05

Video resource

15 minutes
Fireship, "React in 100 Seconds" Open on YouTube
Programming with Mosh, "React Tutorial for Beginners" Open on YouTube

Watch "React in 100 Seconds" first, for the big picture. Then watch the Mosh tutorial from the beginning for the rest of the block, focusing on the parts about components, JSX and props. The tutorial sets up its project with a different tool from the one you'll use today; that's fine, because the React parts are the same.

Guided viewing questions:

  1. In your own words, what does it mean that the UI is "a function of state" (or of data)?
  2. Why do component names start with a capital letter?
  3. What are props, and who decides their values?
06

Reading resource

15 minutes
React, "Your First Component"react.dev React, "Passing Props to a Component"react.dev

React, "Using TypeScript", the section on typing component props react.dev

Guided reading questions:

  1. According to the React docs, why shouldn't you define a component inside another component?
  2. What is the difference between props and the "children" prop?
  3. Show, from memory, how to type the props of a component that takes a name (text) and an optional rate (number).
07

Interactive exercise

40 minutes

Inside today's Tracker app, once you've created it (the first step of section 10), so you only download Next.js once. Work in app/page.tsx and components/; the Build block replaces the practice code.

  1. 15 min By hand: write a LearnerCard component with typed props (name, rate), and render three of them from an array with map and a key.
  2. 10 min Break it on purpose: pass rate="90" as text, misspell a prop name, and remove the key. For each, note what the editor or console says.
  3. 15 min With AI: ask your AI assistant for a StatusBadge component that shows "On track" or "At risk" depending on a rate. Before using it, write down what each line does. Change anything you'd do differently, and note why.
08

AI-assisted learning prompt

A useful prompt after the assistant has written a component for you:

Prompt

Here is a React component you wrote for me: [paste it]. Walk me through it line by line in plain words. Then tell me which lines a beginner is most likely to misunderstand, and ask me two questions to check that I understand them.

Log it in the AI-use journal: what it wrote originally, the walkthrough, your answers to its questions, and anything you changed.

09

Knowledge check

15 minutes
  1. Explain, in plain words, how React keeps the page in step with the data.
  2. Write a typed LearnerCard component from memory that takes name and rate.
  3. Why does every item in a list rendered with map need a key, and why is the array position a bad choice?
  4. What does TypeScript add to JavaScript? Give one bug it would have caught in your Day 6 or Day 7 code.
  5. In a Next.js app, what are app/page.tsx and app/layout.tsx each for?
  6. What's the difference between export default and a named export, and how does each change the import line?
  7. Your AI assistant asks to run a command you don't recognise. What do you do before you allow it?
10

Build block: Learner Project Tracker

2 hours

The Tracker becomes a Next.js app. Keep your Week 1 repository and GitHub Pages site as they are (they're your Week 1 record), and start a new repository for the app.

  • Create the app outside your Week 1 repository folder: npx create-next-app@latest tracker, and accept the recommended options (TypeScript, ESLint, Tailwind CSS, the App Router). You can keep writing normal CSS this week; Tailwind is optional. Run it with npm run dev, then clear the starter content out of app/page.tsx.
  • Create a new, empty GitHub repository (no README, licence or .gitignore: the app already has its first commit), connect it, and push (git remote add origin …, git branch -M main, git push -u origin main).
  • On a branch, build the main layout in app/layout.tsx: a <nav>, a <main> around {children}, and a <footer>, shared by every page. The navigation can link to pages you'll add on Friday; a "not found" page for those links is fine for now.
  • In lib/learners.ts, define a Learner type, move your learner data in as a typed array, and add a typed attendanceRate.
  • Build two reusable, typed components: LearnerCard and StatusBadge (on track or at risk), and show the learner list on the home page with them.
  • Open a pull request and merge it into main.
11

Flex hour: open-source practice

Optional

Do your three journals first (about 20 minutes). Then use the time to catch up on today's Build work. If you're on track, the optional open-source practice from Week 1 Day 5 (forking, cloning and a real pull request) is a good use of the rest.

12

Deliverables and submission criteria

Nothing is submitted today. Today, build section C (Components and types) of your Tracker Frontend Pack, which you hand in with your P1 scope document for Quest 2 by Sunday 29 Nov, 11:59 pm WAT. Section C should contain:

0 of 7 ticked Ticks are saved on this device only.

13

Daily journal reflection

Add today's entry to your three running journals (they're section E of your Frontend Pack):

  • Engineering journal: What setting up Next.js involved, and anything that went wrong on the way. Estimate vs actual: for today's Tracker milestone, record your estimate, the actual time, and the reason for any big gap.
  • AI-use journal: Every piece of code the AI wrote today: what you asked, what it produced, what you kept, changed or rejected, and why.
  • Curriculum journal: After two days of building the page by hand, did React make sense more quickly? Was today the right point for AI to start writing code?