mirror of
https://github.com/supabase/supabase.git
synced 2026-07-04 15:24:24 +08:00
20 lines
544 B
TypeScript
20 lines
544 B
TypeScript
import useSWR from 'swr'
|
|
import { Notification } from '@supabase/shared-types/out/notifications'
|
|
|
|
import { get } from 'lib/common/fetch'
|
|
import { API_URL } from 'lib/constants'
|
|
|
|
export const useNotifications = () => {
|
|
const { data, error, mutate } = useSWR<Notification[]>(`${API_URL}/notifications`, get)
|
|
|
|
const anyError = (data as any)?.error || error !== undefined
|
|
const refresh = () => mutate()
|
|
|
|
return {
|
|
notifications: anyError ? undefined : data,
|
|
isLoading: !anyError && !data,
|
|
isError: !!anyError,
|
|
refresh,
|
|
}
|
|
}
|