- Full-Stack React Projects
- Shama Hoque
- 56字
- 2021-06-25 21:45:17
Listing users
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 = () => {
return fetch('/api/users/', {
method: 'GET',
}).then(response => {
return response.json()
}).catch((err) => console.log(err))
}