0

I am learning restful-react and trying to use the useMutate feature as a POST request but I need to include a payload. I see in the documentation there is the options to mock data to the console but Im not sure of how I can I actually include the data to send to the backend?

this is an example of my request:

const { mutate: hitLogger } = useMutate({
    path: API_URL_LOGGER,
    verb: 'POST',
    requestOptions: {
      headers: {
        ...API_BASE_HEADERS,
        Authorization: `Bearer ${userToken}`,
      },
    },
    mock: {
      error: error,
    },
  })

useEffect(() => {
 
if(error){
      hitLogger()
    }
  }, [error])

Do I need to send the error as a param to the hitLogger function?

CourtneyJ
  • 458
  • 6
  • 19

1 Answers1

0

I figured it out. The body is passed as a param when the function is called and the request Post it so the proper way to do it is like this:

const { mutate: hitLogger } = useMutate({
    path: API_URL_LOGGER,
    verb: 'POST',
    requestOptions: {
      headers: {
        ...API_BASE_HEADERS,
        Authorization: `Bearer ${userToken}`,
      },
    },
    mock: {
      error: error,
    },
  })

useEffect(() => {
 
if(error){
      hitLogger({
       data: {data: data}
        )
    }
  }, [error])
CourtneyJ
  • 458
  • 6
  • 19