Fix error handling logic in use Notification hook

This commit is contained in:
Joshen Lim committed 2022-06-07 16:44:18 +08:00
1 parent 7bf981e0fa
commit f86e425e6e
1 file changed
+3 -2
+3 -2
View File
@@ -6,11 +6,12 @@ import { API_URL } from 'lib/constants'
export const useNotifications = () => {
const { data, error, mutate } = useSWR<Notification[]>(`${API_URL}/notifications`, get)
const anyError = error !== undefined
const anyError = (data as any)?.error || error !== undefined
const refresh = () => mutate()
return {
notifications: anyError ? undefined : data,
notifications: anyError ? [] : data,
isLoading: !anyError && !data,
isError: !!anyError,
refresh,