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

101
Visualizações
How to get that Apollo Client is refetching specific query?

There are several places in the app where specific query is refetched after different mutations.

Example:

// Some component
const [setUserLocation, setUserLocationResult] = useMutation(setUserLocationMutation, {
  refetchQueries: [{ query: getRecommendationsQuery }],
});

And in my RecommendationsComponent I want to know that this query is loading, but useQuery's loading doesn't update when getRecommendationsQuery is refetched.

const {
  data,
  loading, // this loading is false all the time except first loading
} = useQuery(getRecommendationsQuery);

I can try put useQuery's refetch to the context and use it everywhere rather than refetchQueries prop, but is there a better way to achieve that without that dirty hack - either make loading work or subscribe to that info using apollo client?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

useQuery Hook will call the api only once. You need to call the refetch function to call it again

const {
  data,
  loading, 
  refetch: getRecommendations // <- use this function to refetch the data
} = useQuery(getRecommendationsQuery);

This will also update the loading state

about 4 years ago · Juan Pablo Isaza Relatório

0

I got two answers in github for that question, combined them both and it finally worked:

Pass notifyOnNetworkStatusChange: true to useQuery:

const { data, loading } = useQuery(getRecommendationsQuery, {
  notifyOnNetworkStatusChange: true
});

Pass documents, not objects to refetchQueries prop:

// Some component
const [setUserLocation, setUserLocationResult] = useMutation(setUserLocationMutation, {
  refetchQueries: [getRecommendationsQuery],
});
about 4 years ago · Juan Pablo Isaza Relatório

0

When the query is refetched, the data will be updated. You can subscribe to changes in the data object returned from the useQuery hook:

const {
  data,
  loading,
} = useQuery(getRecommendationsQuery);

useEffect(() => {
  console.debug("data has changed!", data]);
}, [data]);
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