Skip to content

[Feature Request] Better support for prefetching with hooks (react-query) #1061

Open
@rcwestlake

Description

@rcwestlake

Is your feature request related to a problem? Please describe.
I'm building a Next.js app and using zenstack + react-query hooks. I want to prefetch a query when hovering over the link. Both Next.js and React Query have the ability to do that but when using hooks generated by zenstack, it's challenging because:
a) since querying is happening client side, the Next.js prefetch doesn't help
b) the queryKey used by zenstack is complex

Describe the solution you'd like
Add an alternative key structure that is simpler

Describe alternatives you've considered

  • Potentially support additional keys or tags for hooks so that we can add a custom key e.g. deal-${id} so we can easily refetch

For now, I plan to not use the provided hook and create my own that I can prefetch / invalidate.

Additional context
For example, when I use a hook to query a record, the queryKey used by zenstack is long and complex

["zenstack","Workspace","findFirst",{"include":{"Pipeline":{"include":{"Deals":true,"PipelineStages":true}}},"where":{"id":4}},{"infinite":false,"optimisticUpdate":true}]

I can hardcode for that but it seems brittle.
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions