Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

236
Vistas
Calling React hook in a function

Is there a chance I can run a query with a useQuery hook only if the button is clicked?

const handleClick = () => {
  const [, { data }]  = useLazyQuery(GET_ORDER_INVOICE, {
    variables: { order_Id: orderNumber }
  });

  return '';
};

<Button
  priority={ButtonPriority.SECONDARY}
  onClick={ () => {
    handleClick();
  } }
/>

However, this breaks with the React Hook "useLazyQuery" is called in function "handleClick" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. Is there a chance I can bind calling a query to a button click?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You need to call useLazyQuery in the body of your component. It will then return to you a function that you can call in handleClick:

const Example = () => {
  const [executeQuery, { data }] = useLazyQuery(GET_ORDER_INVOICE);

  const handleClick = () => {
    executeQuery({
      variables: { order_Id: orderNumber }
    })
  }

  // ...
  <Button
    priority={ButtonPriority.SECONDARY}
    onClick={handleClick}
  />
}
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda