React Exercises
Fill in the blanks to check your knowledge. Each exercise belongs to a lesson.
React Introduction
Exercise
Which word names a reusable piece of UI?
A React Get Started
Exercise
Start the dev server.
npm run JSX Syntax
Exercise
The JSX name for the HTML class attribute.
<div ="box">
JSX Expressions
Exercise
Insert a value.
<p>{}</p>
Fragments and Rendering
Exercise
Mount the app.
createRoot(el).(<App />)
Project Structure
Exercise
Entry file name.
src/.jsx
Function Components
Exercise
Component names start with a ___ letter.
Start with a letter
Props
Exercise
Pass a prop.
<Greeting ="Ada" />
Children and Composition
Exercise
The special prop name.
function Card({ })
Conditional Rendering
Exercise
Render nothing.
return ;
Lists and Keys
Exercise
Add the special attribute.
<li ={i.id}>
Styling Components
Exercise
Inline style takes an ___.
style={{ color: "red" }} is an Importing and Exporting Components
Exercise
Import a default export.
import Button "./Button"
Pure Components
Exercise
Pure functions give the same ___ for the same input.
Same input, same Handling Events
Exercise
Run on click.
<button ={f}>
The useState Hook
Exercise
Create state.
const [n, setN] = (0)
State Updates and Snapshots
Exercise
Updater form.
setN(n => n 1)
State with Objects and Arrays
Exercise
Copy an object.
{ user, age: 21 }
Controlled Inputs
Exercise
Read the typed text.
e.target.Lifting State Up
Exercise
Where should shared state live?
The common Forms and Submit
Exercise
Stop the reload.
e.()
useState
Exercise
Setter call.
(n + 1)Functional Updates
Exercise
Previous value.
setN((c) c + 1)
State with Objects
Exercise
Copy then change.
setUser({ user, age: 31 })
State with Arrays
Exercise
Remove an item.
items.((i) => i.id !== id)
Handling Events
Exercise
Stop default.
e.()
Passing Arguments to Handlers
Exercise
Arrow wrapper.
onClick={() onPick(id)}
Controlled Inputs
Exercise
Read the typed text.
e.target.Checkboxes and Selects
Exercise
Checkbox state.
e.target.Forms and Submit
Exercise
Submit event.
<form ={submit}>
Lifting State Up
Exercise
Shared owner.
The state lives in the Lazy Initial State
Exercise
Function initialiser.
useState(() 0)
Resetting State with key
Exercise
Reset trick.
<Profile ={userId} />
Checkbox, Select and Textarea
Exercise
Checkbox property.
e.target.A Todo List
Exercise
Remove an item.
list.(x => x.id !== id)
Derived Values
Exercise
Calculate a sum.
items.((s, i) => s + i.p, 0)
Form Validation
Exercise
Check the length.
v.pw. < 8
Keys and Resetting State
Exercise
The attribute that resets state.
<Profile ={id} />
Sorting and Filtering Lists
Exercise
Copy an array.
[arr]
The useEffect Hook
Exercise
Run once on mount.
useEffect(fn, )
Effect Cleanup
Exercise
Cleanup returns a ___.
return () => clearInterval(id) is a Fetching Data
Exercise
Parse JSON.
r.()
The useRef Hook
Exercise
Read the stored value.
ref.You Might Not Need an Effect
Exercise
Compute during ___.
Compute during Strict Mode and Development Checks
Exercise
Wrapper component.
<React.Mode>
Routing with React Router
Exercise
Link component prop.
<Link ="/about">
useReducer
Premium exercise. See plans
Context
Premium exercise. See plans
useMemo and useCallback
Premium exercise. See plans
React.memo
Premium exercise. See plans
Custom Hooks
Premium exercise. See plans
Rules of Hooks
Premium exercise. See plans
Lazy Loading with Suspense
Premium exercise. See plans
Error Boundaries
Premium exercise. See plans
Portals and forwardRef
Premium exercise. See plans
useId, useTransition and useDeferredValue
Premium exercise. See plans
Server Components and Frameworks
Premium exercise. See plans
Choosing State Management
Premium exercise. See plans
Testing Components
Premium exercise. See plans
Performance Tips
Premium exercise. See plans
Accessibility
Premium exercise. See plans
React with TypeScript
Premium exercise. See plans
Project Organisation
Premium exercise. See plans
Environment, Build and Deploy
Premium exercise. See plans
React Best Practices
Premium exercise. See plans
Next Steps
Premium exercise. See plans
JSX Rules
Exercise
Attribute for CSS class.
<div ="box">
Expressions in JSX
Exercise
Embed a value.
<p>{}</p>
Fragments
Exercise
Short fragment.
<>
Inline Styles
Exercise
Style object.
style={ color: "red" }}
Conditional Rendering
Exercise
Show only if true.
{ok <p>Yes</p>}
Lists and Keys
Exercise
Required list attribute.
<li ={n.id}>
Function Components
Exercise
Capital letter.
function () {}
Props
Exercise
Default prop.
function G({ n, age 18 })
The children Prop
Exercise
Nested content.
function P({ })
Spreading Props
Exercise
Forward props.
<button props} />
Import and Export
Exercise
Default import.
Button from "./Button";useEffect
Exercise
Dependency array.
useEffect(fn, )
Effect Cleanup
Exercise
Cleanup function.
return () => (id);
Fetching in an Effect
Exercise
Stale guard.
let = false;
Dependency Rules
Exercise
Run once.
useEffect(fn, )
useRef
Exercise
Read the ref.
ref.useMemo
Exercise
Cache a value.
(() => calc(), [a])useCallback
Exercise
Cache a function.
(() => {}, [])useReducer
Exercise
Send an action.
({ type: "inc" })Context
Exercise
Read context.
(Theme)Custom Hooks
Exercise
Naming rule.
function Toggle() {}
Rules of Hooks
Exercise
Top level.
Call hooks at the level
useId and useLayoutEffect
Exercise
Link a label.
<label ={id}>
useTransition
Exercise
Mark non urgent.
const [p, ] = useTransition();
Composition over Inheritance
Exercise
Reuse by combining.
Use not inheritance
Render Props
Exercise
Prop is a function.
render={(p) <b>{p.x}</b>}
Higher Order Components
Exercise
Wraps and returns.
A HOC returns a Portals
Exercise
Render elsewhere.
(node, document.body)Error Boundaries
Exercise
Catch render errors.
Error catch render errors
lazy and Suspense
Exercise
Loading UI.
<Suspense ={<p>Wait</p>}>
React.memo
Exercise
Skip renders.
React.(Row)
Refs to Children
Exercise
Pass the ref.
<input ={ref} />
Typing Props
Exercise
Mark required.
PropTypes.string.Container and Presentational
Exercise
Pure display.
A component only renders
Compound Components
Exercise
Share via context.
Tabs and Tab share Conditional Classes
Exercise
Choose a class.
active "on" : "off"
Routing Basics
Exercise
Navigate.
< to="/about">
Route Parameters
Exercise
Read params.
const { id } = ()
Loading and Error States
Exercise
Early return.
if (loading) <p>Wait</p>;
Debouncing Input
Exercise
Delay.
setTimeout(fn, )
Persisting State
Exercise
Save.
localStorage.(k, v)
Theme Switcher
Exercise
Provide a value.
<ThemeCtx. value={x}>
Project: Todo App
Exercise
Add an item.
setTodos([...todos, ])
Project: Stopwatch
Exercise
Stop the timer.
return () => (id);
Project: Live Search
Exercise
Case insensitive.
i.().includes(q)
Derived State
Exercise
Compute in render.
const total = items.(fn, 0)
StrictMode
Exercise
Wrapper.
<><App /></StrictMode>
Common Mistakes
Exercise
Safe update.
setItems([items, x])
Accessibility
Exercise
ARIA label.
<button -label="x">
Testing Components
Exercise
Render in a test.
(<App />);Project Structure
Exercise
Keep small.
Components should be Starting a Project
Exercise
Start dev server.
npm run Environment Variables
Exercise
Prefix.
API_URL=xWhy Not Index Keys
Exercise
Stable.
key={x.}
Event Bubbling
Exercise
Stop it.
e.()
Actions and use
Exercise
Form attribute.
<form ={save}>