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
Sean Unpaved
2 hours agoKirk Herbstreit Joins The Show! | UNPAVED
114 watching -
1:00:36
Timcast
2 hours agoTHEY HAVE CAVED
149K37 -
1:12:54
BonginoReport
3 hours agoMinneapolis Mayor Needs a Reality Check! - Scrolling w/ Hayley Caronia (Ep.228)
77.7K38 -
2:04
Simply Bitcoin
20 hours ago $0.30 earnedRumble Wallet Walk Through
12K2 -
LIVE
Wendy Bell Radio
5 hours agoTerm Limits Fix All This
5,517 watching -
1:07:03
Framers View
3 hours agoFramersView
7.93K -
LIVE
LFA TV
17 hours agoLIVE & BREAKING NEWS! | WEDNESDAY 2/4/26
2,257 watching -
1:48:42
The Dan Bongino Show
5 hours agoThe Looming Threat That Nobody Is Talking About (Ep. 2445) - 02/04/2026
724K936 -
1:06:01
The Rubin Report
3 hours agoIlhan Omar Finally Got Scared After New Proof of Her $5M Winery Fraud Just Went Viral
50.3K31 -
1:04:25
Trumpet Daily
3 hours ago $0.70 earnedGadi Taub Interview - Trumpet Daily LIVE | Feb. 4, 2026
25.2K3