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

270
Visualizações
React Query: get query status

React Query has a useful hook called useIsFetching (see docs), which allows checking whether a given query is currently fetching data, like so:

const queryCount = useIsFetching(['my-query-name'])

I want to do something very similar: I want to know for a given endpoint, if data has already been fetched (isFetched).

I know this is returned from the useQuery hook, but using this hook would call the endpoint again, and I want to avoid the repeated call.

Any ideas how to achieve this?

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

0

You can avoid calling the endpoint again by setting a staleTime on your query, because in that time, data will come from the cache only.

if data doesn't exist yet, it will be fetched. If you don't want that, consider queryClient.getQueryState(['my-query-name']). However, this will not create a subscription, so your component will not re-render if the query state changes.

about 4 years ago · Juan Pablo Isaza Relatório

0

Solved by utilizing useQuery's enabled property, which allows defining whether or not to make the request.

useQuery(
    ['my-query-name', requestPayload],
    () => callMyEndpoint(requestPayload),
    {
        // ...
        enabled: booleanToIndicateWhetherToEnable,
    }
)
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