Updating a user's data

The update method will take changed user data from the view component for a specific user, then use fetch to make a PUT call to update the existing user in the backend. This is also a protected route that will require a valid JWT as credential.

mern-skeleton/client/user/api-user.js:

const update = (params, credentials, user) => {  return fetch('/api/users/' + params.userId, {    method: 'PUT',    headers: {      'Accept': 'application/json',      'Content-Type': 'application/json',      'Authorization': 'Bearer ' + credentials.t    },    body: JSON.stringify(user)  }).then((response) => {    return response.json()  }).catch((err) => {    console.log(err)  })}

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.