Increment version to 2.14.1 and refactor notifications stream hook

- Bumped package version in package.json from 2.14.0 to 2.14.1.
- Refactored the `useNotificationsStream` hook to remove unnecessary `useQuery` and streamline the subscription logic for real-time notifications, enhancing performance and clarity.
This commit is contained in:
gbuomprisco
2025-09-17 12:48:42 +08:00
parent 533dfba5b9
commit 530e127000
2 changed files with 20 additions and 27 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "next-supabase-saas-kit-turbo", "name": "next-supabase-saas-kit-turbo",
"version": "2.14.0", "version": "2.14.1",
"private": true, "private": true,
"sideEffects": false, "sideEffects": false,
"engines": { "engines": {

View File

@@ -1,7 +1,5 @@
import { useEffect } from 'react'; import { useEffect } from 'react';
import { useQuery } from '@tanstack/react-query';
import { useSupabase } from '@kit/supabase/hooks/use-supabase'; import { useSupabase } from '@kit/supabase/hooks/use-supabase';
type Notification = { type Notification = {
@@ -20,13 +18,10 @@ export function useNotificationsStream(params: {
}) { }) {
const client = useSupabase(); const client = useSupabase();
const { data: subscription } = useQuery({ useEffect(() => {
enabled: params.enabled,
queryKey: ['realtime-notifications', ...params.accountIds],
queryFn: () => {
const channel = client.channel('notifications-channel'); const channel = client.channel('notifications-channel');
return channel const subscription = channel
.on( .on(
'postgres_changes', 'postgres_changes',
{ {
@@ -36,16 +31,14 @@ export function useNotificationsStream(params: {
table: 'notifications', table: 'notifications',
}, },
(payload) => { (payload) => {
console.log('payload', payload);
params.onNotifications([payload.new as Notification]); params.onNotifications([payload.new as Notification]);
}, },
) )
.subscribe(); .subscribe();
},
});
useEffect(() => {
return () => { return () => {
void subscription?.unsubscribe(); void subscription?.unsubscribe();
}; };
}, [subscription]); }, [client, params]);
} }