next-query-glue
v0.0.6
Published
> Tiny glue layer between next.js and react-query (or any other fetching library).
Downloads
417
Readme
next-query-glue
Tiny glue layer between next.js and react-query (or any other fetching library).
Installation
$ npm install next-query-glue
$ yarn add next-query-glue
Getting started
Starters
react-query + View Transitions API
That library exports:
- NextQueryGlueProvider that should wrap your application. It will slightly modify router singltone.
- prepareDirectNavigation, function that makes pages router skip next data/middleware call and display page immediately. Should be called before navigation.
- getQueryKey is a function that returns key for the current page. Basically, it's just an url of the page, but without a hash part.
- getQueryFn is an async function that calls route data/middleware.
Benefits
- usePageData() for getting route data, no more props drilling.
- Fetch library agnostic, you can use anything.
- Supports most next.js versions.
- Doesn't break default router behaviour.
- View Transitions API works better.
- Lets your api work slow. Potentially, 300-600 ms lag can be invisible within optimistic navigation.
- All the benefits of react-query/rtk-query/swr. Like caching, optimistic navigation, persistence storage etc.
Drawbacks:
- Complicates the code. Now your components needs to handle situation when route data is loading.
- Routes that trigger NextResponse.rewrite will act like prepareDirectNavigation wasn't called. As workaround, you can pass pathModifier function in NextQueryGlueProvider to rewrite paths on the client side.