From ef549156cd54c094ff04da054638690198f41bfa Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Fri, 27 Dec 2024 15:11:23 -0600 Subject: [PATCH] Actually, memo should work here --- .../queries/trending/useTrendingTopics.ts | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/state/queries/trending/useTrendingTopics.ts b/src/state/queries/trending/useTrendingTopics.ts index de57be8322..757e6a6f7e 100644 --- a/src/state/queries/trending/useTrendingTopics.ts +++ b/src/state/queries/trending/useTrendingTopics.ts @@ -9,6 +9,11 @@ import {useAgent} from '#/state/session' export type TrendingTopic = AppBskyUnspeccedDefs.TrendingTopic +type Response = { + topics: TrendingTopic[] + suggested: TrendingTopic[] +} + export const DEFAULT_LIMIT = 14 export const trendingTopicsQueryKey = ['trending-topics'] @@ -20,7 +25,7 @@ export function useTrendingTopics() { return preferences?.moderationPrefs?.mutedWords || [] }, [preferences?.moderationPrefs]) - return useQuery({ + return useQuery({ refetchOnWindowFocus: true, staleTime: STALE.MINUTES.THREE, queryKey: trendingTopicsQueryKey, @@ -33,21 +38,24 @@ export function useTrendingTopics() { suggested: data.suggested ?? [], } }, - select(data) { - return { - topics: data.topics.filter(t => { - return !hasMutedWord({ - mutedWords, - text: t.topic + ' ' + t.displayName + ' ' + t.description, - }) - }), - suggested: data.suggested.filter(t => { - return !hasMutedWord({ - mutedWords, - text: t.topic + ' ' + t.displayName + ' ' + t.description, - }) - }), - } - }, + select: React.useCallback( + (data: Response) => { + return { + topics: data.topics.filter(t => { + return !hasMutedWord({ + mutedWords, + text: t.topic + ' ' + t.displayName + ' ' + t.description, + }) + }), + suggested: data.suggested.filter(t => { + return !hasMutedWord({ + mutedWords, + text: t.topic + ' ' + t.displayName + ' ' + t.description, + }) + }), + } + }, + [mutedWords], + ), }) }