Fetching the create post API in the view

We will update the api-post.js to add a create method to make a fetch call to the create API.

mern-social/client/post/api-post.js:

const create = (params, credentials, post) => {  return fetch('/api/posts/new/'+ params.userId, {    method: 'POST',    headers: {      'Accept': 'application/json',      'Authorization': 'Bearer ' + credentials.t    },    body: post  }).then((response) => {    return response.json()  }).catch((err) => {    console.log(err)  })}

This method, like the user edit fetch, will send a multipart form submission using a FormData object that can contain the text field and the image file.

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.