Clients
SWR client
The SWR Client is our default client for React projects. It's a lightweight wrapper around the SWR library from Vercel.
Installation
Note: The client depends on SWR version 2.0.0.
Configuration
Let's start by configuring WunderGraph. We're using templates.typescript.client
to generate our base client that will be used to create typesafe hooks.
Create the hooks
WunderGraph comes with a powerful framework for generating code. Here we are creating fully typed SWR hooks based on the operations of our WunderGraph application.
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.