Async/Await
This tag groups the examples where the shape of the asynchronous call is part of the answer: awaiting a response before reading it, keeping a rejection distinct from a failed status, cancelling an await that is no longer needed, and narrowing a payload after the promise resolves. Entries show the full function signature so the reader can see where the await belongs, and each one names the failure that appears when the keyword is missing from a caller. Use the task groups to compare request lifecycle work with in-memory reshaping of the value you awaited, then follow the relationship links to reach the typed variants of the same flow.
This is a controlled cross-cutting tag: it groups Examples that share one facet, not a bounded topic. In scope:Include when the solution code uses async/await control flow as a necessary part of the answer. Out of scope: Exclude synchronous transformations and thenable chaining described only in prose.
5 published examples.
Fetch API data
3 examplesSend a request, await the response, and handle status, timeout, and cancellation behaviour.
Cancel an in-flight fetch with AbortController
Abort a pending request when the input changes or the view unmounts, so a slow response cannot overwrite a newer one or update a dead component.
Fetch JSON and separate a failed request from a failed status
Await a JSON response, then branch on transport failure, HTTP status, and malformed body separately instead of catching everything together.
Type a generic fetch hook that returns a known payload
Wrap fetch in a hook whose generic payload type is proven by a runtime predicate, so a component only renders data it has already accepted.
Transform data
2 examplesReshape collections and records in memory into the structure the next step needs.
Narrow an unknown API response with type guards
Layer small type predicates over an unknown response and return a narrowing result, so the compiler only exposes fields a runtime check has accepted.
Normalize an API payload into a typed list
Unwrap whichever envelope an API returns, check each row field by field, and get one typed list plus a named reason for every entry that was dropped.
Adjacent navigation
- Parent: Home
- Related topic: Data Transformation
- Related topic: Fetch and HTTP
- Related topic: React State
- Or search: Search examples