April 2020
Intermediate to advanced
716 pages
18h 55m
English
The list method will use fetch to make a GET call to retrieve all the users in the database, and then return the response from the server as a promise to the component.
mern-skeleton/client/user/api-user.js:
const list = async (signal) => { try { let response = await fetch('/api/users/', { method: 'GET', signal: signal, }) return await response.json() } catch(err) { console.log(err) }}
The returned promise, if it resolves successfully, will give the component an array containing the user objects that were retrieved from the database. In the case of a single user read, we will deal with a single user object instead, as demonstrated next.
Read now
Unlock full access