In this guide, we'll learn how to handle realtime data in Supabase using server actions and react query.
We implemented notifications as a realtime feature in Nextbase Ultimate and we can use that as a reference.
Supabase Realtime
Supabase provides a realtime service which can be used to listen to changes in your database.
When used with a React client component useEffect it looks something like this:
In the above code, we are listening to changes in the user_notifications table and refetching the data when a change occurs.
Depending on the scenario, you can also just use the payload from the realtime data to setState or update a react query cache directly.