Hi all, I am trying to listen to real-time supabas...
# help
g
Hi all, I am trying to listen to real-time supabase updates in my react-native app, but for some reason no matter what I do I can't get it to work. I have set up replication under supabase_realtime for all my tables last night because I noticed it wasn't enabled for all tables, thinking this would fix it. Real-time update listening is still not working unfortunately. When I print the status it says "CLOSED" by the way. I also don't have RLS enabled on my tables. Here is the code in my useEffect hook: useEffect(() => { const messageSubscription = supabaseClient .from('\*') .on("\*", (payload) => { console.log("GOT HERE") } ) .subscribe((status) => { console.log(status) }); return () => { supabaseClient.removeSubscription(messageSubscription); }; } }, []); Would appreciate any help, been stuck for a long time 😦. Real-time listening appears to only work when the code is outide of useEffect, but this would mean it makes hundreds of subscriptions (I think) which is unsustainable of course.
n
Hello @gtims123! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
g
Is it possible your useEffect is running before you have the client fully initialized? You seem to imply that if you just move the code outside of useEffect it works. Do you get to see any network traffic in both cases? It could be alot of things, if your code was not working at all, but replication and those kinds of things had to be set up correctly for it to work outside of useEffect.
n
gtims123 (2022-05-21)
k
You might also try moving the message subscription into a state variable or something. Not 100% sure it's not getting dropped when the useEffect closure is disposed. I'd expect it to be held by the cleanup function closure but I don't know the useEffect internals
g
Still not working, I posted here https://github.com/supabase/supabase/discussions/6947 I've tried many things, including not using useEffect, debug print statements, etc.