Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 14.1 — How React Apps Get Data
React · Example 2 of 3

Starting both requests together

Both requests start at 0 ms and the page is ready at 500 ms: twice as fast, with the same server.

React apps load data in four main ways: in effects, through a data library, in route loaders, or in server components; the big difference between them is when a request starts, and starting late causes slow request waterfalls.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

A Dashboard renders <Stats /> and <Alerts />; each fetches in its own effect. Is this a waterfall? Explain, then write a version where Alerts only renders after stats load and say what changes.

02

Rewrite this to start both requests at once: const user = await getUser(id); const orders = await getOrders(id);.

03

Write a React Router route object with a loader that loads a product and its reviews in parallel, and the component that reads them.

Explain it without notes

01

Name the four main ways a React app gets data and one strength and one weakness of each.

02

What is a request waterfall, why do effects tend to create them, and how do you fix one?

03

Explain fetch-on-render, fetch-then-render and render-as-you-fetch.

04

Why does React's documentation steer people away from fetching in effects for production apps?

Starting both requests together

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

start user at 0 ms
start posts at 0 ms
got user at 500 ms
got posts at 500 ms