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

116
Views
How to inject parameters into return function with custom hook react

Usually when we use <input /> field in html, we get a callback function such as <input onChange = {(event) => console.log(event.target.value)} How is this event argument passed back to us?

I am trying to do something similar, where I use a custom hook that, when called, does some other logic, and then can return back callback functions and inject arguments into them. For example:

const hello = useHello({
    arg1 : 'person name',
    onSuccess : (response) => {
         // I can now use the response
    }
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In your hook you just create a response however you need to, and then pass it to the onSuccess function that was passed in.

For example:

function useHello({
  arg1,
  onSuccess
}: {
  arg1: string,
  onSuccess: (response: Response) => void
}) {
  fetch(`/?${arg1}`).then((res) => {
    onSuccess(res)
  })
}

Playground

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!