Skip to content

Commit 170065c

Browse files
committed
chore: update next-todo example to use new Realtime API
1 parent 04f66b4 commit 170065c

File tree

2 files changed

+10522
-364
lines changed

2 files changed

+10522
-364
lines changed

example/next-todo/components/TodoList.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,30 @@ export default function Todos({ user }) {
1111

1212
useEffect(() => {
1313
fetchTodos()
14+
1415
subscription1 = supabase
15-
.from('todos')
16-
.on('UPDATE', (v) => console.log('UPDATE on todos', v))
17-
.on('INSERT', (v) => console.log('INSERT on todos', v))
16+
.channel('todos-table-channel')
17+
.on('realtime', { event: 'UPDATE', schema: 'public', table: 'todos' }, (v) =>
18+
console.log('UPDATE on todos', v)
19+
)
20+
.on('realtime', { event: 'INSERT', schema: 'public', table: 'todos' }, (v) =>
21+
console.log('INSERT on todos', v)
22+
)
1823
.subscribe((change) => console.log('todos changed', change))
1924

2025
subscription2 = supabase
21-
.from('*')
22-
.on('UPDATE', (v) => console.log('UPDATE on schema', v))
23-
.on('INSERT', (v) => console.log('INSERT on schema', v))
26+
.channel('public-schema-channel')
27+
.on('realtime', { event: 'UPDATE', schema: 'public' }, (v) =>
28+
console.log('UPDATE on schema', v)
29+
)
30+
.on('realtime', { event: 'INSERT', schema: 'public' }, (v) =>
31+
console.log('INSERT on schema', v)
32+
)
2433
.subscribe((change) => console.log('schema changed', change))
34+
35+
return () => {
36+
supabase.removeAllChannels()
37+
}
2538
}, [])
2639

2740
const fetchTodos = async () => {
@@ -34,7 +47,7 @@ export default function Todos({ user }) {
3447
}
3548
const addTodo = async (taskText) => {
3649
try {
37-
supabase.removeSubscription(subscription2)
50+
supabase.removeChannel(subscription2)
3851

3952
let task = taskText.trim()
4053
if (task.length) {

0 commit comments

Comments
 (0)