diff --git a/src/providers/queries/notificationQueries.ts b/src/providers/queries/notificationQueries.ts index 3a38bd8b3..9a9945344 100644 --- a/src/providers/queries/notificationQueries.ts +++ b/src/providers/queries/notificationQueries.ts @@ -5,7 +5,7 @@ import { useQueries, useQueryClient, } from '@tanstack/react-query'; -import { useEffect, useState } from 'react'; +import { useState } from 'react'; import { useIntl } from 'react-intl'; import { unionBy } from 'lodash'; import bugsnapInstance from '../../config/bugsnag'; @@ -20,7 +20,6 @@ import QUERIES from './queryKeys'; const FETCH_LIMIT = 20; export const useNotificationsQuery = (filter: NotificationFilters) => { - const [data, setData] = useState([]); const [isRefreshing, setIsRefreshing] = useState(false); const [pageParams, setPageParams] = useState(['']); @@ -37,11 +36,6 @@ export const useNotificationsQuery = (filter: NotificationFilters) => { return lastId; }; - const _onSuccess = () => { - const dataArrs = notificationQueries.map((query) => query.data); - const _data = unionBy(...dataArrs, 'id'); - setData(_data); - }; // query initialization const notificationQueries = useQueries({ @@ -49,7 +43,6 @@ export const useNotificationsQuery = (filter: NotificationFilters) => { queryKey: [QUERIES.NOTIFICATIONS.GET, filter, pageParam], queryFn: () => _fetchNotifications(pageParam), initialData: [], - onSuccess: _onSuccess, })), }); @@ -74,8 +67,10 @@ export const useNotificationsQuery = (filter: NotificationFilters) => { } }; + const _dataArrs = notificationQueries.map(query => query.data); + return { - data, + data: unionBy(..._dataArrs, 'id'), isRefreshing, isLoading: notificationQueries.lastItem.isLoading || notificationQueries.lastItem.isFetching, fetchNextPage: _fetchNextPage,