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.
-
LIVE
The Tom Renz Show
1 hour agoElection Fraud, the GOP, & Corruption w/ Liz Harris
124 watching -
1:02:02
Timcast
2 hours agoGOP Office TORCHED By Terror Attack, Elon Says ARREST Democrat Billionaires Funding Attacks
155K139 -
1:54:09
Steven Crowder
4 hours agoSocial Security Scandal: How Elites Use Illegals to Game The American System
355K257 -
1:12:06
The Rubin Report
3 hours agoBill Maher Makes Gavin Newsom Look Dumb with Simple Questions
55.3K31 -
1:51:49
Benny Johnson
2 hours ago🚨 Trump CONFIRMS He Is Running For President AGAIN | Libs FREAK as Experts Say Third Term POSSIBLE
81.1K54 -
1:01:04
VINCE
4 hours agoWisconsin Decides The Future Of The World | Episode 11 - 03/31/25
295K211 -
52:12
Grant Stinchfield
2 hours ago $1.20 earnedTexas AG To Investigate Muslim Centric Communities and The Quest to Take Over America
20.2K4 -
33:56
Rethinking the Dollar
2 hours agoThe Bigger Issue Is War, Not A Silver Squeeze | Morning Check-In
31.9K8 -
LIVE
Flyover Conservatives
12 hours agoNathan French Drops Prophetic Bombs About Trump, Revival & America’s Future | FOC Show
525 watching -
DVR
The Shannon Joy Show
2 hours ago🔥🔥Nothing Is Changing - In Fact It’s Getting Worse. But This Weekend’s #SummitForTruth In New York Gave Us Reason For HOPE And A Path To Liberty & Normalcy.🔥🔥
25.4K3