Demo, all content is generated
Question

Supabase realtime subscription fires but the list does not update

Solved · 223 views · asked by sam_builds · edited

I subscribe to postgres_changes on orders. The console logs every insert, but the list on screen only updates after a refresh.

What I’ve tried

Added the payload to state with state.push(payload.new).

Comment

1 answer

Marked as helpful by the asker
dev_ana · edited

state.push mutates the array in place; React compares references and sees no change. Create a new array:

setOrders((prev) => [...prev, payload.new]);

Also enable Replication for the table (Database → Replication) or you won't get events at all in production, even though local seems to work.

Comment
The push. Of course. sam_builds · edited
Also remove the channel in the effect cleanup, otherwise in dev with StrictMode you get two subscriptions and every insert shows up twice. jb_supa · edited