You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Supabase Cache Helpers does a decent job at keeping your data up-to-date. This allows you to deviate from the standard configuration and reduce the number of requests to your backend while keeping your app fresh.
7
6
8
7
<Tabsitems={['SWR', 'React Query']}>
9
-
<Tab>
8
+
<Tabs.Tab>
10
9
```tsx
11
10
function Page() {
12
11
return (
@@ -21,10 +20,10 @@ Supabase Cache Helpers does a decent job at keeping your data up-to-date. This a
@@ -75,13 +74,13 @@ Import [`useQuery`](./queries#usequery) and define a simple query. The cache key
75
74
}
76
75
```
77
76
78
-
</Tab>
77
+
</Tabs.Tab>
79
78
</Tabs>
80
79
81
80
Somewhere in your app, import [`useInsertMutation`](./mutations#useinsertmutation) and define a mutation. For the automatic cache population to work, you need to pass the primary key(s) of the relation as a second argument. To return data from the mutation, pass a `.select('...')` string as the third argument. Pass `null` to skip. The fourth argument is the SWR- and React Query-native `options` object. The mutation will automatically update the query cache of the contact query defined above. Other operations are supported with [`useUpsertMutation`](./mutations#useupsertmutation), [`useUpdateMutation`](./mutations#useupdatemutation) and [`useDeleteMutation`](./mutations#usedeletemutation).
@@ -126,15 +125,15 @@ Somewhere in your app, import [`useInsertMutation`](./mutations#useinsertmutatio
126
125
}
127
126
```
128
127
129
-
</Tab>
128
+
</Tabs.Tab>
130
129
</Tabs>
131
130
132
131
To subscribe to changes, import [`useSubscription`](./subscriptions#usesubscription) and define a subscription. Use any channel name, and define the subscription as you know it from the Supabase client. For the automatic cache population to work, you need to pass the primary key(s) of the relation. You can pass the SWR and React Query-native mutation options.
133
132
134
133
The query cache will automatically be updated when new data comes in. If you use [computed / virtual columns](https://postgrest.org/en/stable/api.html?highlight=computed%20columns#computed-virtual-columns) or relations, you can use [`useSubscriptionQuery`](./subscriptions#usesubscriptionquery) to fetch the entity from `PostgREST` before populating the cache with it.
0 commit comments