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

255
Visualizações
React-Query fechQuery not keeping data in cache

I'm using react-query version 4.0.0-beta.12 and I'm caching data up front while application is loading by using queryClient.fetchQuery. The problem is when I refresh the page, the cached data will be disappeared from localStorage.

// query client instance with default option
const queryClient = new QueryClient();

// fetch data upfront while application is loading
await queryClient.fetchQuery(key, () => Promise.resolve(data), {
       staleTime: 3_600_000, 
       cacheTime: 43_200_000,
       meta: {
           offline: true
       }
});

<PersistQueryClientProvider
    client={queryClient}
    persistOptions={{
        persister: createWebStoragePersister({ storage: window.localStorage }),
        dehydrateOptions: {
            shouldDehydrateQuery: (query) => !!query.meta?.offline
        },
        maxAge: Infinity
    }}
>
    <App />
</PersistQueryClientProvider>
 

query.meta.offline after first refresh of page becomes undefined.

please be noted that I'm not attending to pass the meta as a defaultOption to qurtyClient instance. I have other queries using the same instance which I don't want to cache their data.

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