Introduction
Realtime lets apps show updates instantly without refreshing. It helps users see changes as they happen.
Realtime lets apps show updates instantly without refreshing. It helps users see changes as they happen.
const subscription = supabase .from('table_name') .on('INSERT', payload => { console.log('New row:', payload.new) }) .subscribe()
This code listens for new rows added to a table.
Use .on() to specify the event type like INSERT, UPDATE, or DELETE.
const subscription = supabase .from('messages') .on('INSERT', payload => { console.log('New message:', payload.new) }) .subscribe()
const subscription = supabase .from('tasks') .on('UPDATE', payload => { console.log('Task updated:', payload.new) }) .subscribe()
This example connects to Supabase, listens for new rows in the 'chat' table, and logs new messages instantly.
import { createClient } from '@supabase/supabase-js' const supabaseUrl = 'https://xyzcompany.supabase.co' const supabaseKey = 'public-anonymous-key' const supabase = createClient(supabaseUrl, supabaseKey) const subscription = supabase .from('chat') .on('INSERT', payload => { console.log('New chat message:', payload.new) }) .subscribe() // Simulate waiting for new messages setTimeout(() => { console.log('Listening for new messages...') }, 1000)
Realtime uses WebSockets to keep a live connection open.
Remember to unsubscribe when you no longer need updates to save resources.
Realtime lets apps update instantly without page reloads.
It listens for database changes like new rows or updates.
This makes apps feel fast and interactive for users.
messages in Supabase?from('table').on(event, callback).subscribe().messages table and INSERT event.tasks table?
supabase.from('tasks').on('INSERT', payload => console.log(payload.new)).subscribe()payload.new.payload.new containspayload.new holds the new row data inserted into the table.supabase.from('orders').on('UPDATE', payload => console.log(payload)).subscribe()
What is the likely problem?subscribe() and uses correct event UPDATE, so syntax is fine.orders table in Supabase settings.Pass the test and this pattern moves unknown