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.
-
1:10:24
Keepslidin
4 hours ago30K START | UFC 314 | ROAD TO 100K | Mother.land
32 -
DVR
Spartan (Pro Halo esports Player)
4 hours agoPro Halo Scrims vs SSG!
381 -
LIVE
blockysplashy
1 hour agoROAD TO HERESY ACT 1, 2 & 3 COMPLETION!+XUR IS HERE!😃
54 watching -
3:00:01
Barry Cunningham
7 hours agoPRESIDENT TRUMP FINISHES STRONG! THE WEEK IN REVIEW AND MORE NEWS
22.1K23 -
24:09
MYLUNCHBREAK CHANNEL PAGE
1 day agoDams Destroyed Egypt
37K53 -
14:38
Exploring With Nug
9 hours ago $1.77 earnedYou Really Never Know What You'll Find Underwater! UNBELIEVABLE!
13.2K1 -
41:43
Jamie Kennedy
5 hours agoThe Decline of Beverly Hills, Forgotten Sound Frequencies, and Elon Musk Criticism | Ep 201 HTBITY
24K12 -
1:09:53
Game On!
9 hours ago $5.48 earnedThe Masters Day 3 LIVE Reaction!
45.2K -
23:14
CatfishedOnline
1 day agoVictim scammed out of $100,000 for 8 years!
53.4K17 -
17:30
Bearing
12 hours agoTHIS is why Men Shouldn’t Compete in Women's Sports 🤣
37.6K75