Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
Including a body in useMutate using restful react

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

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])
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!