Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement useQuery prefetching #821

Closed
flybayer opened this issue Apr 25, 2020 · 3 comments · Fixed by blitz-js/blitz#546
Closed

Implement useQuery prefetching #821

flybayer opened this issue Apr 25, 2020 · 3 comments · Fixed by blitz-js/blitz#546

Comments

@flybayer
Copy link
Member

Both of the following should cache the getProduct query, same as if it was used with useQuery

const product = await getProduct({where: {id: props.id}})
<button onMouseEnter={() => getProduct({where: {id: productId}})}>
  View Product
</button>
  • This functionality needs to be added in the rpc.ts file in the core package.
  • It needs to use the same computed cache key as used inside the blitz useQuery.
  • It needs to use queryCache.setQueryData from react-query to actually set the cache

Then end-result is that once prefetched like shown above, then the next call of useQuery(getProduct, {where: {id: productId}}) will return the cached data.

@flybayer
Copy link
Member Author

Let me know if you want to work on this but need more information about how to build it!

@ivandevp
Copy link
Contributor

Hey @flybayer ! I can work on this. I'll probably need more information but I can start by checking how react-query works for this case and understand how to add it to Blitz ⚡.

@flybayer
Copy link
Member Author

@ivandevp sounds good! :)

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

Successfully merging a pull request may close this issue.

2 participants