Clients
Next.js client
The Next.js client uses SWR under the hood.
Installation
Configuration
Add NextJsTemplate
to your WunderGraph configuration:
Hooks
useQuery
This hook accepts most useSWR Options except for key and fetcher.
Calling mutate
will invalidate and refetch the query.
useQuery (Live query)
You can turn any query into a live query by adding the liveQuery
option.
useMutation
This hook accepts most useSWRMutation Options except for key and fetcher.
useSubscription
useAuth
useUser
This hook accepts most useSWR Options except for key and fetcher.
File upload
This hook accepts most useSWRMutation Options except for key and fetcher.
SSR
Wrapping the App or Page in withWunderGraph
will make sure that Server Side Rendering (SSR) works, that's it.
Global Configuration
You can configure the hooks globally by using the SWRConfig context.
In case the context configuration isn't working, it's likely due to multiple versions of SWR being installed or due to how PNPM or Yarn PnP link packages. To resolve this you can import SWR directly from @wundergraph/nextjs
to make sure the same instance is used.