April 2020
Intermediate to advanced
716 pages
18h 55m
English
In order to use the shop list API in the frontend, we will define a fetch method that can be used by React components to load this list of shops. The list method on the client side will use fetch to make a GET request to the API, as shown in the following code:
mern-marketplace/client/shop/api-shop.js:
const list = async (signal) => { try { let response = await fetch('/api/shops', { method: 'GET', signal: signal }) return response.json() }catch(err) { console.log(err) }}
As we will see in the next section, this list method can be used in the React component to display the list of shops.
Read now
Unlock full access