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() {
1616
1717You 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
2022import { useRealtime } from ' react-supabase'
2123
Original file line number Diff line number Diff 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+
2830export 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 (
You can’t perform that action at this time.
0 commit comments