Skip to content

Commit 94456d5

Browse files
committed
fix: generic
1 parent febf69b commit 94456d5

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

docs/pages/documentation/realtime/use-realtime.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ function Page() {
1616

1717
You can pass a function for comparing subscription event changes. By default, the compare function checks the `id` field.
1818

19+
When using your own compare function, you typically want to compare unique values:
20+
1921
```js highlight=6
2022
import { useRealtime } from 'react-supabase'
2123

src/hooks/realtime/use-realtime.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ export type UseRealtimeCompareFn<Data = any> = (
2525
payload: Data,
2626
) => boolean
2727

28+
type CompareFnDefaultData<Data> = Data & { id: any }
29+
2830
export function useRealtime<Data = any>(
2931
table: string,
30-
compareFn: UseRealtimeCompareFn = (a, b) => a.id === b.id,
32+
compareFn: UseRealtimeCompareFn<Data> = (a, b) =>
33+
(<CompareFnDefaultData<Data>>a).id ===
34+
(<CompareFnDefaultData<Data>>b).id,
3135
): UseRealtimeResponse<Data> {
3236
if (table === '*')
3337
throw Error(

0 commit comments

Comments
 (0)