Menu

Post image 1
Post image 2
1 / 2
0

Stop Fetching Data Sequentially When It Could Be Parallel

DEV Community·ReactChallenges·23 days ago
#sv1OeA5j
Reading 0:00
15s threshold

Picture this: you fetch a list of items from an API, and for each item you need extra data from a different endpoint. The natural instinct is to loop through the items and fire a request for each one — maybe inside a useEffect , maybe with an await inside a .map . The code works. The data shows up. But if you look at the network tab, every request waits for the one before it, and your loading spinner sits there for seconds longer than it should. This is sequential fetching of independent data , and it is one of the easiest performance wins you can grab in any frontend app. 👉 Try it in practice: Rick & Morty: Double Fetching The trap Imagine you are building a page that displays characters from the Rick & Morty API. The characters come from https://rickandmortyapi.com/api/character/?page=1 , and for each character you also want to show the title of their first episode. That episode title lives at character.episode[0] — a separate URL.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More