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.
-
14:22
Robbi On The Record
2 days ago $0.20 earnedGen Z’s Narcissism Obsession: Why Everyone’s a “Psychologist”
19K8 -
LIVE
GritsGG
5 hours agoQuad Win Streaks!🫡 Most Wins in WORLD! 3600+
204 watching -
1:09:28
Sarah Westall
3 hours agoCan the World Be This Strange? The Nature of Our Reality w/ Darius J Wright
20.7K -
megimu32
3 hours agoOn The Subject: Friends | 31 Years of the Sitcom That Defined a Generation
27.1K4 -
30:00
BEK TV
1 day agoCounter Culture Mom
5.04K -
1:24:54
Kim Iversen
6 hours agoTylenol vs Vaccines: Which One Is The REAL Cause Of Autism? The Truth Will Upset You
58.4K60 -
LIVE
GloryJean
4 hours ago2v2 Tuesday 🔥 Night Games w/ The Boys 🖱️ 6.7 K/D
12 watching -
LIVE
XxXAztecwarrior
6 hours agoNew Season/ War Ablaze
23 watching -
LIVE
Armadillofather
3 hours agoTime for some Borderlands Chaos! | Thank you for being here!
9 watching -
1:03:39
TheCrucible
6 hours agoThe Extravaganza! EP: 41 (9/23/25)
282K18