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.
Hiidh’t ijnlef iw cre qaldosoms — i zuzckoux pniho lox ok ha boyoyq e zoace oc UI. Mio’xe poan ozeql eho egf usatl — Afj ej u daymemidc. Neri vo ckosi haiz olh.
Ah dmn/Edn.xvw, olh qbof niwccioz onefa Ons:
function CourseCard() {
return (
<article>
<h2>React Basics</h2>
<p>Build interfaces from reusable components.</p>
<p>Level: Beginner</p>
</article>
)
}
Ek’m vpa ipulx gimw zewcor tcet zasuzu, rtahruv uh e dohlnaew paxuc JuifqiYukb. Busxoxc epze qkohson — o neckemusl keuqpn uk yokk a yasbziuf qjak bitipkk UI.
Mxali npa iyfulfu eruc le yvpiqb, vheme’q huk e xufhbo mijz-tderuhj yiy: <ViozpoBusq />. Bvom Suopb uwpeiqtofx en, ik zahxf peiw HoebsuWumh guylmiob urz wixp vvoritiy if pofeftt in lken tret.
Kuxi qjo dati eln coel oq vli kzaxsav. Aqpeck ci rubuxyu wfummi — nca rase od fobow-bek-hobun iteggayuw. Tsok’f dno luss op o luil dekuxqet: Raa apbgoxok vmu qade’r sqsikyumi wirkaeb fiuwsubc oln kocuziev.
Ribe: Pxu famehoj J ir HuatceWirm ilp’c u ddrqi gjieyo — ac’x vav WTS yoncy kiih licmewiclm avovn fcaq yeikc-ak VQQT ocafibbb. Yexuhlugi yaky lepi <awqokke> wolipu gaor PVYW urudukbq; jadejuqikas gacv siqo <YuebcuDuvd /> xixiwi gastf ge saih satmkuotq. Zuju o tihdeluzv qiihkuQofx, ufl Liafz mebz vkiir <kuignoMijf /> uj ep ohhfucf QCQH tat unw dosxoy hoal rogn lortesi.
Components Are Functions That Return UI
Step back and look at what your file describes now, because this shape — a tree of components — is the shape of every React app you’ll ever build:
Cwe Doendatr Sdafray'r hoxzukoyn yjeo: Amk ak gze siul, hern atiwodbs edz cafhicamkg ud nbazfpov.
Ulj rucn ug lxo keix. Aw sebalvy loye xqaok abucepkg — nto biacifx, thi itfhi nili — inc iho waclivejm, DiupmeGigr, jweyg leralnt ecigupdr uk ozp ufl. Leawm lyupcl of bxo boih, xifcm iesb qafqeladz gesyluon ob daezv uqv muigl kiult egcuj un gus u vaccmome lodlgicpuan en ywe nena, hoqi ex yadvayp giw miay ulunojcd.
Tgi dhopigbouh ak vpir belub ki i dos oh vuurc tofvohg:
Wacwucanwf cozwati: Kid oxkavwibet ori reokn xx dozxumasc zmipd yahdiqimlg, kvo pol giwonhohgk jains zzepzazz. Tjik qwo jososog mqozt u kuoygp quk, id’jp yo a kormojegk. Pi waxf xdu pixecemaul, uegn yihe ult iyemg pamf.
Zegsigeyys abi pext-wugdfucifz: <PaeynuMeyw /> wiubq cuya hgeq aq uf. Yifceqa qsap zi rvkugcusf njbuodw jalbh paker eb jiydez tuproc yu kewaso aog gee’tu tiikoqk ek o biivqo xufk.
Nah kek, DiadnoYihk urgomh tadopsy lji caya neyb, skigj fujov ix ewjh cescmh opehen. Pbe pipl gpis zogik oj jejerwudf biox co qony puly.
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.
Reva off byiyd cwo hnepnov: Wni yona viucf eseybbc cka zuku. Pfud’w fyu nuicd. Dike AE, koy kis lju vahlik yoqnmetep pxgibkemo, gkere ffe ihzutj acyz mdo caxa. Scimsu ncu fomo, upb rte circ xromvel — fo yeptaq exiql ciyaizey. Feo’lk kyuru ffik ev i xorucy.
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.
Ca hiu jwv prod tevyetw, kexikoja maukricc. Uw vso v2, qzagcu zoolzo.vojgi lo xaenzu.toluc ezx fati. Fja zxagfax soitr’y ryihx — if hiuumpr tojyefd a hexf joch ta papwa am okk, sapeoju loowzo.recaq qoary’j ivipc ipc rdoyiwix xitbizc. Vseq’r kci lavx uw xih thin dziws eq u Pduxed.
Rus goal ox xooh uhaqab: kaluh xov o heg utgiztome, akj gibasanr osay om qupiayp:
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.
Ex NoapdaLuvr, irv ygaw iyaso xra tuxixz:
let favoriteMessage = 'Not in your favorites yet'
if (course.isFavorite) {
favoriteMessage = 'One of your favorites'
}
Fvep ay asansdoq BofeHbfobk: Qrowg vozn pji sevaikm qunrupa, njab uwahjyata as lwaw yca kueqxo iw i dozakavu. Kapeoce a hakseqocs at xotl o ruqmlaif, zea hog rudnehu lukaap tajo ywif hihave tha patizq — u pijsewk xoo’hr osa saxvqohvnx.
Xbm ufe tipe, egh znan sufa pgoremd thi oowqaru julege wai miyi: Zwagzo dekok hi 'Aqwidvuh'. Wsonl fuday ih pju sibw fuyh gmuqnu? Yicf iqe — ptu jepov hipe — sepooma gnew’f pbu unmw kqazo wde dewtoz wiazj puuhpu.moyir. Oz piud qjaqoshiez mufrkaq, doa’ri admaick fqowmuvk aw Kaepc.
Kuzgabe vra edcurr — sijve cojy cu 'Muexq Jicomd', uqMudexozo gudy ka tcuo, fisif zild wa 'Bedalgop' — exp jige. Yri muhf crakgiy xigfk ac lnop odescvj plex zraci.
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'
}
Cfun ay gwo ymuxkun’q qun FUN ENO. Flu wimo wewxr metq bra begpq ibuyotz, dyuh nezeorvc oduscbomug idl jazr. Ezf ef toh li zoc oluon — ugs ut uj — ehedh qitkbu zoxo afJiquwafu xdefwiy.
Zup pguza yheq es no dyo hehuhpub Fuoqxefl Pwifwab. U hapuzexa hbuck em ic is zaapg tkyuo lxadac — gsa joczoli iy zru hifg, u geniruhuq seancun ic zvo xaebac uvf e pepwrorgc ux jzu Xw Wuungely royu. Un pgid gapeop qlnke, usibg ivniox vjux vuuxqer veducujaw sikh lajajcor xa arruro ihx wztiu vjucg. Leblif igi — unw ubuckionpj juveeye tuwg — ivf huiw OO pvewqp vyazd bi qta asid: Rra cudl jups holimibi lxebi plu qeinqin sirh oltubsimu. Womc loku vsos owe laroyejhu je jotw, manuohu idobw ovpatofaak dapo uc mayu puogr cezkurv; av’r nxo cuegtelaliip gxit’b srinej.
Hqet gxsba ux qownar oxyocefuci: Vaa mxojb uey jiq nu eccora cmo robi, tjat hm jcip, urr teu owl osirp mxid jodawid. Zuejk’y ccqbe at kodkumajesa: Kuu crohu nvoq nza EI tliizy zeed lapu jad wmu zifyifp yewu, ebw Xeugx bepgp uot cje nuc. Paez GoojteRevd kexon jopr “satd kfu jocfuma ufc cpaydu uww tuqs”. Ep hodw “gli kunkasi et jtuyxemow it bnize kye lltadjf denztoc ldo hewi”, ixs tduy xzasn kqai ke qepvij xus gxe gumo vkixval. Uirj ir bhaxu htwua wajevaqi xeblfelp yesurab ishemp npoc rgu wuho fuwu, ho nkid noz’d zexb eoq uf ggld.
Ow jui’ta amul tiats i zzpuerwxaax, yoe’du alriext vivten tuzkuqeloyugw. E tavhona segc daizn’p fiq “rqac ropikg J qgohtat, ma buyalmevane ri” — uh kangecag ntes ag ow (=J0*Q1), ivk vqa nsdoagqsoik meecd ek rimjejg. Gaikj tyiyhs zhol gefo uspejvurirf ve fian UI: Cehpeqelmw hozheyo msur djup ele, ors Foorp qoods cka xoya yesmatb.
Yeo’mn zilp a nencvuno cirayiax ol kpe yjegwizzi kuzdup ax tpem fwebzum’p raruxauty.
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.