From 998484a6827d7e51273455716b84cb1319be5a34 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 28 Sep 2024 14:09:22 +0100 Subject: [PATCH] only enable query when needed --- src/components/player/player-scores.tsx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/components/player/player-scores.tsx b/src/components/player/player-scores.tsx index 26afc6c..cea6a32 100644 --- a/src/components/player/player-scores.tsx +++ b/src/components/player/player-scores.tsx @@ -86,7 +86,6 @@ export default function PlayerScores({ data: scores, isError, isLoading, - refetch, } = useQuery({ queryKey: ["playerScores", player.id, pageState, debouncedSearchTerm], queryFn: () => { @@ -97,7 +96,9 @@ export default function PlayerScores({ ...(isSearchActive && { search: debouncedSearchTerm }), }); }, - staleTime: 30 * 1000, + staleTime: 30 * 1000, // 30 seconds + enabled: + debouncedSearchTerm.length >= 3 || debouncedSearchTerm.length === 0, // Enable if valid search query or empty }); const handleScoreLoad = useCallback(async () => { @@ -127,10 +128,6 @@ export default function PlayerScores({ ); }, [pageState, debouncedSearchTerm, player.id]); - useEffect(() => { - refetch(); - }, [pageState, debouncedSearchTerm, refetch]); - const handleSearchChange = (query: string) => { setSearchState({ query }); };