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

169
Visualizações
Apollo useQuery does not always trigger re-render of function component

This is my functional component that makes use of useQuery from @apollo/client:

function MyComponent(props) {
  const { data } = useQuery<MarketScannerSearchProps>(
    MARKET_SCANNER_SEARCH_PROPS_QUERY,
    {
      onCompleted: (data) => {
        console.log("completed", data)
      },
    }
  )
  console.log("data", data)

  // ... rest of function + return rendered result
}

I get this in my console:

data undefined
data undefined

completed {marketScannerSearchProps: {…}}

why isn't there a data {marketScannerSearchProps: {…}} at the end?

This is not always reproducible, only happens every 5th reload or so of my app. This is how it looks when it works:

data undefined
data {marketScannerSearchProps: {…}}
completed {marketScannerSearchProps: {…}}

So somehow the 2nd time the component is rendered the data is there, but not always, and if the data isn't there by the 2nd render, it never updates it afterwards.

Shouldn't apollo trigger a re-render every time once the query completes? What am I missing here?

EDIT: I think this issue might be gone now. I closed and opened Chrome Dev Tools a few times, and now it seems to be gone. Could it be Apollo client side caching getting messed up?

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