Premium Only Content
Using fetch to Retrieve Message Data for React App
The lecture goes over the use of fetch to retrieve data for the messages in a React application.
The Fetch API can be used to make an HTTP request to a backend server such as an API that serves data in the JSON format.
With a GET request, the default behavior of fetch, data for messages in a chat room-like user interface are retrieved.
The call to fetch returns a Promise that fulfills with a Response object.
You can extract the body of the response and interpret its text content as JSON, thus creating a JavaScript object with the mapped information. This is also known as deserialization or unmarshalling.
The json method of the response object can be called to extract the body of the response and read it as JSON, thus creating a JavaScript data structure with the data. In the example, it creates an array of objects.
Note the return value of the call to json is another Promise that fulfills with the deserialized value, so another call to then is necessary. Having multiple then statements in a row can be called a promise chain.
The map method of the array is used to transform it into another array with the relevant information.
The array of things that represent each message are then used to set the React state for messages.
-
4:52:00
Drew Hernandez
1 day agoTRUMP CALLS ON AMERICA TO MOVE ON FROM EPSTEIN AS DOJ COVERS UP FOR MONSTERS IN EPSTEIN FILES?
50.1K24 -
2:39:31
ThatStarWarsGirl
6 hours agoTSWG LIVE: Helen of DeTROYt Debate!
41.7K8 -
2:10:46
TheSaltyCracker
7 hours agoMel Was Right About Hollywood ReeEStream 02-04-26
105K155 -
48:44
LFA TV
1 day agoMAKE MEN..MEN AGAIN!
28K6 -
1:08:07
AlaskanBallistics
7 hours ago $0.48 earnedI Love this Gun PodCast #88
20.1K2 -
1:11:00
MattMorseTV
7 hours ago $10.54 earned🔴CHAOS in the SENATE.🔴
41.9K166 -
6:56:14
GritsGG
10 hours ago25 W Streak Camo ✅! #1 Warzone Victory Leaderboard 1205+ Ws!!🔥
18.6K1 -
2:25:58
Barry Cunningham
8 hours agoLIVE BREAKING: President Trump Televised Interview | Kristi Noem | Super Bowl Players Speak!
106K24 -
1:23:46
This is the Ray Gaming
6 hours ago $0.10 earned1v1 Me Bro Podcast Special Guest Yin is NGMI | Rumble Premium Creator
10.3K -
8:08:15
SpartakusLIVE
9 hours ago#1 Solo Challenge CHAMPION || MASSES Flock to Sparta to WITNESS the ULTIMATE Gaming OVERLORD
27.4K3