UI frameworks: what they are and why they exist. React as an example (typed props and state in a few lines), with Vue, Angular, and Svelte mentioned
TaskKit's page, kept right by hand, forgets its count. See why UI frameworks draw a page from its data, then write it in React with typed props and typed state, running on the page, and read the same component in Vue, Angular and Svelte.
TypeScript
React
UI frameworks: what they are and why they exist. React as an example (typed props and state in a few lines), with Vue, Angular, and Svelte mentioned. Read this lesson at .
Tested with TypeScript 7.x · Node.js LTS
In the last lesson your Clear button did two things on every
click: it emptied the list, and it set the count back to 0. Now
your friend asks for a Remove button beside each task. You
write it in a few minutes, press it, and the task disappears. Above
the list the page still says Tasks: 3 over two tasks: this time
the line for the count is the one you forgot.
Every line you wrote works. The page shows the tasks in two
places, the list and the count, and the new button changed one of
them. Every button you add next, Done, a filter, an undo, has
to remember every place that shows the tasks. In this lesson you
see the other way to build a page, the one UI frameworks are made
for: keep the tasks in one place and let the page be drawn from
them. By the end, TaskKit's page is written in React, and
TypeScript checks every piece of data the page is drawn from.
Two ways to keep a page right
In the last lesson every click changed the page itself. That is
keeping the page right by hand.
The other way is to keep the data apart, in an array in your code,
tasks, and to write one function that draws the page from it.
Handlers no longer touch the page: they change tasks, then ask
for the page to be drawn again. The count cannot fall behind the
list on the page, because both are drawn from the same tasks
every time.
main.ts
function clearTasks() { list.textContent = ""; count.textContent = "0";}
By hand
Does: Empties the list, then sets the count
Never: Keeps the list and the count matching by itself
main.ts
function clearTasks() { tasks = []; render();}
From the data
Does: Empties the tasks, then draws the page from them
Never: Has a line for the count that can be forgotten
By hand, a handler updates each place; from the data, it
changes the data
Here is that second way in plain TypeScript, with no framework.
tasks is the data, render draws the list and the count from
it, and the two buttons only change tasks. Press Run, add a
few tasks on the page under the code, then press Clear.
A real page has many parts: tasks, a filter, a menu, a form.
Writing a render for each, and deciding which ones to call after
each change, is work every web page needs. That is the work a UI
framework does for you.
What a UI framework does
A UI framework (UI is short for user interface, the part of a
program people see and click) is a library that keeps a page
matching your data. You describe what the page should show for
the data you have, and the framework draws it, and draws again
whatever changes when the data does.
You describe the page in components. A component is a
function that returns one piece of the page: a count, a list, a
form. Big pages are built from small components, as big programs
are built from small functions. A component gets its data in two
ways:
Props are values passed in by the component that uses it,
its parent, as arguments are passed to a function. A count
component gets the number to show.
State is a value the component keeps itself, and can
change. When it changes, the framework calls the component again
and puts what is new on the page.
This lesson uses React, created at Meta, in version 19, the
current one when the lesson was checked on 26 November 2026; new
versions come out, so check react.dev for the one you install.
Vue, Angular and Svelte do the same job in their own way; the end
of the lesson shows the same component in each.
A component in a .tsx file
A React component returns the piece of page it draws, written as tags right
inside the code: return <p>Tasks: 3</p>;. That <p> is not a string. It is
JSX (JavaScript XML, where XML is a language of tags in angle brackets),
tags written as part of the code, which the compiler turns into a call to
React for each tag. A file that holds JSX ends in .tsx (TypeScript with
JSX) instead of .ts, so TypeScript knows to read the tags. Inside a tag,
braces hold a value from your code, <p>Tasks: {total}</p>, the way ${}
does in a template string.
In your own project, two things make the check read JSX:
"jsx": "react-jsx" in tsconfig.json, and React's types from
the @types/react package, like the @types packages of Level 1.
A tool called Vite, which starts and serves web projects and comes
later in this module in Bundlers and dev servers (Vite),
starts a new React project with both already in place. On this
page they are already set.
The page needs one empty element for React to draw into, usually
<div id="root">. createRoot(root), from the
react-dom/client package, makes a React root on that element,
the place React owns and draws into, and the root's own render
method draws a component into it.
Press Run:
A component is used as a tag of its own, <TaskCount />. Its
name starts with a capital letter: that is how JSX tells your
TaskCount from the page's own <p> and <div>. And
querySelector can find nothing, as in the last lesson, so the
element is checked before React gets it.
Typed props
TaskCount always says 3. To show the real number, it takes the
number as a prop. Props arrive as one object, so you give that
object an interface and take the prop out of it with destructuring,
as Level 1's Module 6 did with a function's parameter:
A prop is written like an attribute, count={2}. The braces
matter: count={2} passes the number 2, and count="2" the
string "2". That is where TypeScript earns its place in a React
project. The check knows TaskCount takes { count: number }, so
every place that uses it is held to that type. Press Edit,
change count={2} to count="2", and press Run: no page is
drawn, and the check says Type 'string' is not assignable to type 'number'. Take the prop out, <TaskCount />, and it says
Property 'count' is missing in type '{}' but required in type 'TaskCountProps'.
Without TypeScript, both mistakes run. The page shows Tasks: 2
from the string, which looks right until someone adds 1 to it and
gets "21", or Tasks: with nothing after it when the prop is
missing. The check finds both on the line where the component is
used, before anyone opens the page.
State: what the page is drawn from
TaskKit's list of tasks changes while the page is open, so it is
state. useState from the react package makes a piece of state:
you give it the starting value, and it gives back two things in a
tuple, the value now and a function that replaces it.
tsx
const [tasks, setTasks] = useState<string[]>([]);
The square brackets take the two out by position, as Level 1's
Module 6 took a tuple apart. The type argument says what the
state holds, a list of strings, as querySelector<HTMLInputElement>
said what it finds in the last lesson. useState is a hook: a
function called only inside a component, at its top, never inside
an if or a loop, because React tells one piece of state from the
next by the order of the calls.
You never change tasks itself. React draws again when setTasks gets a
different list from the one it has, and a list changed with push is still
the same list. So you hand it a new one, setTasks([...tasks, text]), made
with spread as in lesson 6.8, Destructuring and spread (and why spread is
shallow), instead of changing the old one. Press Next to walk through
one click on Add with two tasks already listed, or let it play:
Page
App
React
1
Page to App: onClick:addTask()
2
App to React: setTasks([...tasks,text])
3
React to App: App()
4
App to React: 3×<li>,<TaskCountcount={3}/>
5
React to Page: addone<li>,setTasks:3
One click: React calls App again and changes only what differs
All 5 steps shown.Step 1 of 5: Page → App — onClick: addTask()Step 2 of 5: App → React — setTasks([...tasks, text])Step 3 of 5: React → App — App()Step 4 of 5: App → React — 3 × <li>, <TaskCount count={3} />Step 5 of 5: React → Page — add one <li>, set Tasks: 3
All 5 steps shown.
App returns the whole page as it should now look, and React
compares it with what it drew last time. You never wrote that
comparison, and you never wrote which elements to update.
Here is TaskKit's page as React components. The text box is state
too, text, so React always knows what is typed. Press Run,
then add a few tasks.
onClick and onChange take the function to call, as
addEventListener did. The names are written in camelCase, and
onChange is called on every key the reader types.
event.target.value needs no check and no type argument.
TypeScript knows the handler belongs to an <input>, so it
types event.target as an HTMLInputElement.
tasks.map turns each task into an <li>, and braces put the
list of them on the page. key gives each item a name, so React
can tell the items apart and see which one is new. Two equal
tasks would share a name: add Buy milk twice and the output
shows React's warning, Encountered two children with the same key. A real TaskKit task has an id for its key.
<> and </> hold several tags together, because a component
returns one thing.
The same idea in Vue, Angular and Svelte
React is not the only framework. Vue, Angular and Svelte also
build pages from components with props and state, and all four
check props with TypeScript. They differ in how a component is
written, and in where its HTML (HyperText Markup Language, the
tags of a page) goes. Here is TaskCount in each of the other
three, as each was written when this lesson was checked on 26
November 2026 (Vue 3, Angular 22, Svelte 5); newer versions can
change the details:
Does: A class per component, with forms and page navigation built in
The @Component(...) line is a decorator, a line starting
with @ that adds information to the class under it: here it
tells Angular the class is a component, and its selector is the
tag other templates write to use it, <task-count>.
input.required makes count a prop that must be passed,
<number> says it is a number, and you read it by calling it,
count().
Does: Turned into plain JavaScript before it reaches the browser
$props() hands the component its props, typed by the annotation
on the destructuring, as in React.
One component, three frameworks: each checks count as a number
Vue is made by an independent team, not a big company, and is known for being
easy to start with. Angular, from Google, is a whole toolkit, common in large
companies. Svelte is the newest of the four. In each, passing count a string
fails the check with the words you met above, Type 'string' is not assignable to type 'number'. Each runs that check through its own tool built on
TypeScript, vue-tsc, svelte-check and Angular's compiler, because plain
tsc does not read their templates. What you learned about props and state
carries over to any of them.
Predict before you run
Predict
What type does TypeScript give tasks?
tsx
const [tasks, setTasks] = useState(["Buy milk"]);
The common mistake: useState([])
A list that starts empty is the usual case, and the type argument
is the part that is easy to leave out. Run this:
Common mistake
An empty starting list, and no type for it
The empty list gives TypeScript nothing to read a type from. It
types it never[], a list that can hold nothing at all, and every
task you add is refused.
When an error names never, or null, near a useState, look at
the starting value. An empty list, or null for something that is
loaded later, needs the type written out: useState<string[]>([]),
useState<string | null>(null).
Pass all four tasks to complete the lesson with practice. Reach the end without them and it counts as read only.
Exercises
Three of these exercises have a page with React on it. Press
Run to try the page yourself, and Check when you think it
works.
Exercise · Write the code
Give each task a Remove button
Put a Remove button in each item of the list. Pressing it takes
that task out of the list, and the count follows by itself.
index.htmlhtml
<div id="root"></div>
Loading the editor…
Exercise · Fix the error
Make Add show the task
TypeScript finds nothing wrong with this page, yet pressing Add
shows nothing new. Find out why, and fix it.
index.htmlhtml
<div id="root"></div>
Loading the editor…
Exercise · Write the code
Write a TaskItem with two props
App already uses TaskItem twice. Write it above App, with an
interface for its two props: an item shows its title, and
Buy milk (done) when it is done.
Kept by hand, why does Remove leave the count wrong?
Check yourself
What does React do after setTasks gets a new list?
Check yourself
Why does useState([]) refuse every task?
0 of 0 answered.
A cheat sheet to keep
Cheat sheet
UI frameworks and React
What things are
Word
What it means
UI framework
A library that keeps a page matching your data
Component
A function that returns a piece of the page
Props
Values the parent passes to a component
State
A value a component keeps, and replaces to redraw
JSX
Tags written inside the code
.tsx
A TypeScript file that holds JSX
Hook
A function called only at a component's top: useState
Code
Write
To
interface Props {…}
Say what a component takes
({ count }: Props)
Take the props out
<TaskCount count={2} />
Use it, passing a number
useState<string[]>([])
Make state, with its type
setTasks([...tasks, text])
Replace the state with a new list
onClick={addTask}
Call a function on a click
key={task}
Name each item of a list for React
createRoot(root).render(…)
Draw a component into the page
How it runs
Rule
What it means
Draw from the data
Change the state, never the page
A new value each time
push on state redraws nothing
Type an empty start
[] gives never[], null gives null
Props are checked
A wrong or missing prop fails the check
Where to go next
You can now say what a UI framework is for, write a React
component that takes typed props and keeps typed state, and read
the same component in Vue, Angular and Svelte. React itself is a
course of its own; what you have is the part every React project
stands on.
Next is On the server: Node.js, Deno, and Bun; a typed request
handler: the other end of a page like this one, the program that
answers when the page asks a server for its tasks, typed the same
way.
Before you move on, press Edit on TaskKit's React page above
and make Add ignore a task that is already in the list, so no
two items share a key. Arrays have includes too, as strings do:
tasks.includes(text) says whether the task is there. Then add
Buy milk twice: predict what the list and the output show now
that the second one is ignored, and run it.