Skip to content
Discussion options

You must be logged in to vote

This is really naive, but you could try this:

import { queryCache } from 'react-query'

// Persist to wherever using the super-secret `queries` object

const queriesWithData = Object.values(queryCache.queries).map(query => ({
  queryKey: query.queryKey,
  data: query.state.data
}))

localStorage.setItem('queries', JSON.stringify(queriesWithData))


// Hydrate from localStorage

const queriesWithData = JSON.parse(localStorage.getItem('queries'))

queriesWithData.forEach(query => {
  queryCache.setQueryData(query.queryHash, query.data)
})

This is highly experimental and undocumented, so you can be my guinea pig :)

Replies: 17 comments 13 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by tannerlinsley
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@inoumen
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
10 replies
@harika-sabbella
Comment options

@inoumen
Comment options

@a-eid
Comment options

@kokoskiwi
Comment options

@TkDodo
Comment options

Comment options

You must be logged in to vote
1 reply
@bombillazo
Comment options

Comment options

You must be logged in to vote
1 reply
@TkDodo
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment