File tree Expand file tree Collapse file tree 2 files changed +7
-1
lines changed
docs/pages/documentation/realtime Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ function Page() {
16
16
17
17
You can pass a function for comparing subscription event changes. By default, the compare function checks the ` id ` field.
18
18
19
+ When using your own compare function, you typically want to compare unique values:
20
+
19
21
``` js highlight=6
20
22
import { useRealtime } from ' react-supabase'
21
23
Original file line number Diff line number Diff line change @@ -25,9 +25,13 @@ export type UseRealtimeCompareFn<Data = any> = (
25
25
payload : Data ,
26
26
) => boolean
27
27
28
+ type CompareFnDefaultData < Data > = Data & { id : any }
29
+
28
30
export function useRealtime < Data = any > (
29
31
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 ,
31
35
) : UseRealtimeResponse < Data > {
32
36
if ( table === '*' )
33
37
throw Error (
You can’t perform that action at this time.
0 commit comments