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
BubbaSZN
5 hours ago🔴 LIVE - NOT ENDING UNTIL WE BEAT GTA 5 (DAY 2)
301 watching -
10:20
Stephen Gardner
6 hours ago🔴Trump MUST Unleash Musk's DOGE to Investigate THIS NOW!
50.2K113 -
5:22:42
EXPBLESS
6 hours agoFirst Ever Playthrough (Red Dead Redemption 2) Day 3
14.1K2 -
1:24:46
Winston Marshall
7 hours agoConspiracy Theories & The New Media’s Problem with Noam Dworman
53.5K47 -
LIVE
Tommy's Podcast
6 hours agoE708: RPK Rampage
499 watching -
48:55
Athlete & Artist Show
7 hours ago $2.22 earnedMontreal 100 to 1 To Win The Stanley Cup?!
42.5K2 -
8:38
Talk Nerdy Sports - The Ultimate Sports Betting Podcast
6 hours ago4/19/25 - NBA Playoffs Day 1: Vasil Goes Solo & Destroys the Book 📉🔥
39.6K2 -
58:00
I_Came_With_Fire_Podcast
16 hours agoA Woman's Place is on The Range
35.8K6 -
9:32
Adam Does Movies
1 day ago $2.90 earnedSinners Movie Review - The Best Of The Year?
33.8K3 -
9:50
SKAP ATTACK
1 day ago $2.60 earnedNikola Jokic and the Greatest Season Ever Played
40.9K7