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

213
Vistas
useReactVar in apolloLink cause cannot update component while rendering a diffrend component

i use apollo client and react in project

i want appear loading indicator while network request, so i set react variables and change it inside apollo link

but it cause cannot update component(Indicator) while rendering a diffrend component(component that call useQuery hook)

  • loadingLink.ts
import { ApolloLink } from '@apollo/client';
import { loadingVar } from 'gql/store/reactiveVariables';

export const loadingLink = new ApolloLink((operation, forward) => {
  loadingVar(true);

  return forward(operation).map(data => {
    loadingVar(false);

    return data;
  });
});

  • loadingIndicator.ts
import React from 'react';
import { useReactiveVar } from '@apollo/client';
import { loadingVar } from 'gql/store/reactiveVariables';
import { Indicator } from './Indicator';

const LoadingIndicator: React.FC = () => {
  const loading = useReactiveVar(loadingVar);

  if (!loading) return null;

  return <Indicator />;
};

export default LoadingIndicator;
  • error message

error message

  • BatchList.tsx
const BatchList = () => {
  const {data, error} = useQuery(~~~);

  if(error) return null;
  if(loading || !data) return null;

  return ~~~~
}

in documentation, they say should use useEffect hook but inside ApolloLink i can't use useEffect hook

How can i fix it

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