Real-Time Subscriptions
Subscribe to database changes with supabase.channel, listen for INSERT and UPDATE events on a table, and update the local UI state reactively without polling.
What Are Real-Time Subscriptions?
Real-time subscriptions allow your React Native app to receive database changes as they happen, without polling. When another user inserts, updates, or deletes a row, Supabase pushes the change to all subscribed clients over a WebSocket connection.
This is ideal for chat apps, live feeds, collaborative tools, and any feature where multiple users interact with shared data. Supabase's real-time engine is built on PostgreSQL's logical replication and the supabase-js client handles the WebSocket lifecycle for you.
Enabling Real-Time on a Table
Before subscribing to changes, you must enable real-time replication for the table in Supabase. Go to the Supabase dashboard, open Database > Replication, and add the table to the supabase_realtime publication.
You can also do this with SQL: ALTER PUBLICATION supabase_realtime ADD TABLE your_table;. Without this step, your subscription will connect but receive no events, which is a common source of confusion when first setting up real-time.
-- Enable real-time for the 'messages' table
ALTER PUBLICATION supabase_realtime ADD TABLE messages;
-- Verify which tables have real-time enabled:
SELECT tablename FROM pg_publication_tables
WHERE pubname = 'supabase_realtime';