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

137
Vistas
How to return and use loading from LazyQuery

I'm wrapping the Apollo clients useLazyQuery function as the current function doesn't allow the skip functionality if its the first time you've performed the query.

I'm using

export function useQuery(query, options) {
    const [ execQuery, result ] = useLazyQuery(query, options);

    useEffect(() => {
        if (options.skip !== true) {
            execQuery();
        }
    }, [ execQuery, options.skip ]);

    return result;
}

My codebase contains lots of calls like

  const { loading, data: { getAccount: account = {} } = {} } = useQuery(GET_ACCOUNT, {
    variables: { id: accountID },
    skip: !accountID
    fetchPolicy: 'cache-and-network'
  });

I'm struggling to work out how to return the data and the loading bool from the useLazyQuery function that I've wrapped and store it in the above consts. Currently, it returns the data fine which gets stored in account but I can't get it to return and store the loading bool that useLazyQuery returns.

I've tried:

 const [ loading, execQuery, result ] = useLazyQuery(query, options);

    useEffect(() => {
        if (options.skip !== true) {
            execQuery();
        }
    }, [ execQuery, options.skip ]);

    return [loading, result];

But the result then came back as undefined

about 4 years ago · Juan Pablo Isaza
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