Search code examples
real-timesubscribesupabaseunsubscribesupabase-database

when to unsubscribe from a table (supabase)


I subscribed to listening to inserts on a table in a front end application I have made using react, however in the documentation I've seen that the table is also unsubscribe from in many cases so was just wondering why you need to unsubscribe.

For context, the reason I subscribed was so that I can display the most recent value on the page.

Any answers to this would be greatly appreciated.


Solution

  • One typical case for unsubscribing would be when a user goes to another page, and you are no longer displaying the incoming realtime data to the user. In such case, you might want to unsubscribe.

    In general, you subscribe from the realtime notifications whenever you no longer need the realtime data. In some cases, you might want to keep the realtime listeners connected at all times, because it's a data that is used in every single page of your application. In this case, you don't have to think about unsubscribing from the listener.