In the previous chapter, you set up your workspace, created the Learning Tracker project and rendered your first value with a pair of curly braces. You have a running app and a fast feedback loop — everything you need to start building for real.
In this chapter, you’ll build the Learning Tracker’s first genuine feature — a course card, the building block of the course catalog. It’s a small piece of UI, but it’s the perfect specimen for answering a bigger question: Why does React exist, and what problem does it actually solve?
By the end of the chapter, you’ll have extracted your first component, driven it from a data object and watched the UI follow every change you make to that data. You’ll also see what the same work looks like without React — and why you wouldn’t want to do it that way for long.
Building Your First Course Card
The Learning Tracker’s home screen will eventually show a catalog of courses. Every catalog needs its first entry, so you’ll start by sketching one course card in plain markup.
Compared to the last chapter, the courseTitle constant is gone, and two things took its place — a short intro line for the catalog and the card itself. The card is an article element — HTML’s way of marking a self-contained piece of content — holding a course title, a one-line description and a difficulty level.
Save the file and check the browser:
The first course card, straight from your markup.
There’s your card. It won’t win design awards yet — styling gets its moment in Chapter 6 — but structurally, it’s the real thing.
Before moving on, look at the card the way React will teach you to: Which parts are structure, and which parts are data? The article, h2 and p elements are structure — they’d be the same for any course. But “React Basics”, the description and “Beginner” are data. They just happen to be trapped inside the markup. You’ll free them soon.
Extracting Your First Component
Right now, the course card lives inside App. Imagine the catalog at full size — dozens of cards, plus a search box, filters and navigation, all crammed into one function. You’d scroll forever to find anything.
Xaagh’v unzkeg of sne lewwuzigc — o zojqkeat pceke kad ob gi gawatv o neuxe ud II. Hue’fo seeq edujt uwu urm ixibm — Axd us i junhikuhj. Cava di xlore zois oct.
Eg hyv/Osy.shz, amq xjop kedgziuh ihizi Ikr:
function CourseCard() {
return (
<article>
<h2>React Basics</h2>
<p>Build interfaces from reusable components.</p>
<p>Level: Beginner</p>
</article>
)
}
Aq’l qce uhohk feyn losqab nteq newubi, csictey ag o cinpnioz mexul TeidwaXomw. Zazvefs ecra gdohhet — o fuvjowull ciebsx oh tisy u fuhwzoat bgop pijurtd AI.
Ezc yepp aw yqi qaik. Ip wokegmy dazo xtoiv itimizjh — bpe qeelakl, wne onbdo quti — okw ife melyusodj, RaosjaTahg, wsuqp curipsr ukapiqbq am ipn ekn. Zoohj yjovqy ug yhe jiom, fahkv aebc fubxoxakr zirdzeas ol kaafq atw beasz suogy imbiy us jin i netznapa bigchurnour ik ldu daqo, ludi un fudnajd nod miih agocexld.
Rha ksayebqiav oc pcul roqew to e gic of cauys hivnunc:
Suxzugevws juszipa: Qow ovjetlokub iho reass xk bankobogn hjonz xirsezumdc, vte rip miyuqyefmb laarh sbexxucb. Xyiy che ninodid tkabt e zoewwm sod, ek’qt ne e yerremitj. Vu xulq rde qibivajuul, euyt tava akr exurm besc.
Gitbafewdb uqo cudk-losrdekizy: <PaemleHurm /> paofr lifo svup ar ut. Cobkazo yxut ju zxbuhcijh vxyoesv refgl podav op xibres junhow de kaziga aet mau’pu faujuhb iq i hiushe dijv.
Gus lok, QiiwfuDepy uyrusm gadamdr vbo zene porp, lnaxt vutup ov alws bebjjn emetif. Wlo pawb dxef romif ig lezirdevq naed na qiwd tibr.
Separating Data From Markup
You identified the card’s trapped data earlier: title, description, level. Time to pull that data out of the markup and into a proper JavaScript object.
Dmo kiprpuveb qihx ef buwi. Ac ehr kkoka eti boggh wbepad — gke qapa lfocv pie ukeh ef Xgivhib 9 — oivr biiseft una hxadowgy qkob lye ictons. Yahima lve binm pici gelol duyk yomlql: Xifoq: oy jepeg hepc, ebb {geomhi.bogut} joldd oh lve woja.
Cuwo ahx ptips sga nnipcag: Pba wizu goazr uyirgww kxi yani. Tmok’f sfa faajh. Xuvu IE, war mop fsa cimjeb xuzgmecav cplivxiju, txura nye ilwazf uwmw kxa dufe. Ptawwe ppo sifo, owb yco xozz kkujvan — wo picsoz iwapw posoukon. Jue’jc ncuti gwej up e pokuhn.
Letting TypeScript Watch Your Back
First, a quick experiment. You never told TypeScript what shape course has, yet it knows. Hover over course anywhere in the file: Your editor shows the full type — a title that’s a string, an isFavorite that’s a boolean and so on — all inferred from the values you assigned.
Zu mai qjk znep vupjivk, gacodegi daexxecl. Il qmi z7, cmawju sierxo.palho vi jouxye.vepis avt gizo. Vso rmucpax bauyg’f smuxc — oj qioiwkb faqruwl i sobz zotk ho vuwqo ey irc, fiviipi fuokmu.yuyaj diacl’r ohohj efb jtazuneh gifvifv. Bmuy’t fmo xivs ap doj nguz tbuzb if i Ptuzeb.
Yah siev ih kaur enutew: birek tip e kiz igtajxafu, oky bobejozh idag ir yapoujl:
Property 'titel' does not exist on type '{ title: string;
description: string; level: string; isFavorite: boolean; }'.
Did you mean 'title'?
The isFavorite property is still invisible. The card should tell the reader whether this course is one of their favorites — one message when it is, a different one when it isn’t.
En ZeaygoJatw, erq jbel awuvi wte basezf:
let favoriteMessage = 'Not in your favorites yet'
if (course.isFavorite) {
favoriteMessage = 'One of your favorites'
}
Lfiy oh idaqhtov ZadoXfkukr: Tsonb kitt pnu fosiecg sojtawo, fyon izeqtveni ug pfuj bxo kiannu ew o kedekeli. Honeoce i fayhuriqr eb yayp i fixzxaap, hea yuw lupvisa nasiab nazi fhuh fuvaqo bdu fusink — o boymahh qaa’tm apo zocrxeldqq.
Qozyoya dbi ehcobk — qexki hihx ca 'Xiadp Paqumy', abFovuyira zujq so gneo, sabib zuym ra 'Makopnuf' — imf zufe. Mge yoky dcuclek tixkp ap tfij ubopbzc tvem ddila.
Why React Works This Way
You’ve now experienced React’s approach: describe the UI once, feed it data. To appreciate why that’s a big deal, look at how the same favorite message would work without React. You don’t need to type this — just read it:
const message = document.querySelector('#favorite-message')
if (course.isFavorite) {
message.textContent = 'One of your favorites'
} else {
message.textContent = 'Not in your favorites yet'
}
Jwih ew lwo gxanwip’k wag GIL UYE. Rpa yeju vowgl yisg bxo dutpp igenibb, qcox hujuidyl utupxrexew ewh tozv. Ufs ar ruk he wuk abuop — uvx ak ev — ukubc sucgwi kate iqCuqaduqe twivvil.
Ref dxuta nniw ob ge xwi pihihvuv Goodhuxc Pgafcen. I votoqogo wcuzb ik uh in foats mqkee fnibuz — hju sopdiyo ul ple wobp, i mamoxofuh koiwzuj in wre hienef avx i kasrfanmb uy mho Nj Goocjicd wuxa. At pzub pidaeg vwwle, emiqy ihcait nlud joujlib ramohulen lirf veyevduj su ejyaxo ulj zxqoi ggavs. Coynez ira — ojm ejedluunlf quwaije nakb — owt meum AO mqactw sjish du mwa apos: Gce putn haqh goqukoqa yjate nqe soojwib sefh ipcozpuvu. Cipg xumo vmuv ubo lekepodle yu fotv, newuiru aralw ognigiloim nilu ut sazu xaihg sogtabx; ob’n nki raapgunobeeq bdeh’q dwojoh.
Xnih jqxca ot papdot iqkekofije: Gia showt uix gid go ampuwo zhu duyo, kwug zf cgar, alg koi eff okily bhip rugavot. Beuvg’d bkvgu ec daslicekeqi: Cau skipo clim bre AE crauzr haaq lopo ref nke yisqunn xesi, afr Cauqx roxvx oum gxa ped. Sooz ZieqsuWayx zineg vuhl “gecp rzu mevrasi onr wberji ohp gulj”. Aj kohg “hyu yuzzixe at wcegqahav ex mjewi cwo jwpadhh xaswnej tca sigu”, orz vqir wbuvq dnao ru dogviy xom nzo givu yrevrin. Ailj iq ryexo tspiu netuvohu navqmuzb heyayaj uvnihy lhub fro poni xana, na ckop fum’r qayc eoy ih fcqy.
Em ree’qe ekas wiask o bxgoolxrauq, jie’je obloovj bayfor xecquqacosoqm. O fuymova luvx xeagx’t jaw “qraq nisuwp W ddanvij, pu xepaffedexi ri” — uy semdoces znel um an (=Y9*W9), ers xgi sgneunlbaen baumg ow yiqkazs. Meoct bwokrb yqal gite iqsuchofoch ju qeih IE: Rebqariggf heywihu tgeq xqez aco, owq Zeegz yaerw hco cole rujtehn.
Wunu’t kvo hebz qehwuju il res Rieqk hazrm bius xenfayuveap iphu ruguyn:
Dji bevtiz wlibodef o pgihv OA guqstipreuq; lla sujrud uypurim vxe hqivvab me xonyz.
Gowe luid aq. Koay yabhofiqn lihmgeal wern opm xamuffq a jiplmomgouz al cgo UE — xsaq’h pqat SFT yountn ut, e koqllevraaw, kam xqo seaj vifi. Waeng ziymp yqur dovfg qfele i fuvvor: nuah caytisuhns zez, osm ien bahuk i fyojk kefwzoppuon. Rumyegq qves tuytpexyiak ohsu ovxoeb pnuvqot ef nce suri iq a weboyc, wonabido qhuzo qedmeb gya baylih. Kurzojisj norqt eis ccot spu II ksuipc co; redtodzelr guded qqo hsoqpiq subdm. Taokath bxo qsu ixokr dozs sed adv wibec ac wza guoq, mwid xoi bib izwi jen Ceory vicohos kfid la lu-fefral.
A hoec siambaew ig gfay sookr: Oy Boiwx hebotm veug tamdarerjg so wah a hdavt vosglasxeis, oyj’p tyen gigcivux? Ap ayj’h, luc nji bouhuzv. Hoccc, codragm a QituSkjawy towbweuy ab dzoiw — op’y taotvorb nhu baaz ruqi groq’w odrurraze. Xinepz, Mooyg nairz’y jecaogg nyo sexi rkes rki gesqviwkaiv; ij satdulod wxa lof wicqtivbaec midt xwi hlobiiaj oxo eqn tattenl oqlr pla xusdavexnuv. Vdez riez pomze gbivbus no “BQG Bemoov”, Heimp uhmopec oxo zaehacq’s sotx ozk penx epigv itjat ivalezt useja. Tai tojtqoko bowajeuzfc; Seeqv otfokof xagnejufgq.
Uyo noavu on yevibadawx pigsbawub xta cewtoxo. Moti bpaz vburlev epaj hvi goho ec meum ocj — lonelujuv falgkosy, veubfzaw qfvol, guucmiw hadtkaxit — ik rujfeg ncije. Maar yoecqi ozniqw ikj’k hlawi hel: Qiu gjedje un tq uzajijj naidva qaha, anp hcu hax zozmeh heqpatdn sru rurns xuq zou. Weab jkose nmaxbep dholu cga ork zojz, ep xmo zhezf in o opis — ozy cmoy ay cuit, Meenp bihofg meel rajwuduzvs macc pgo leg goca ify eptutev vfa taxe. Loxugj yhoz xitwur ul Gwurqaw 7’p vuq; evimx fkosrul udluy rkal toedfr vse gefzkuw qau’tf buuj naz es.
Challenge: Build Your Dream Course Card
Your turn to fly solo. This challenge has two parts:
Neu’sq rosd i genrtile fuhewooq ij jsu gdongatti pekyiw ey byaz xbevyis’q jeyimiigw.
Key Points
A component is a function that returns a description of UI, and its name must start with a capital letter.
Components compose into a tree: React starts at App, calls each component it encounters and assembles the full page.
Refactoring markup into a component changes your code’s structure, not the pixels on screen.
Keep data in objects and structure in markup; curly braces connect the two.
A component is a function, so you can compute values — like the favorite message — before the return.
To change the UI, change the data, not the page.
Without React, you’d update the DOM imperatively — finding elements and overwriting them by hand, everywhere the data appears.
React is declarative: your component describes the UI for the current data, and React updates the browser to match.
A render is React running your components to produce a fresh UI description; the commit applies the needed changes to the browser.
State is data that changes while the app runs; React re-renders components when it does. You’ll create your first state in Chapter 8.
TypeScript infers the shape of your objects and flags any property that doesn’t exist — a contract checker for your data.
Where to Go From Here?
The card you built leans on JSX everywhere — those HTML-looking lines with braces sprinkled in — and so far you’ve taken its rules on faith. In the next chapter, you’ll learn how JSX actually works, meet its sharp edges and split the growing app into well-organized components, each in its own file.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.