Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

127
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda