From de314894ff502be85e3b7787ebb2da08945715a7 Mon Sep 17 00:00:00 2001 From: Gigi Date: Wed, 15 Oct 2025 09:44:57 +0200 Subject: [PATCH] fix(explore): properly fix react-hooks/exhaustive-deps warning Instead of suppressing the warning, use functional setState updates to check current state without creating dependencies. This allows the effect to check if blogPosts/highlights are empty without adding them as dependencies, which would cause infinite re-fetch loops. The pattern prev.length === 0 ? cached : prev ensures we only seed from cache on initial load, not on every refresh. --- src/components/Explore.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/components/Explore.tsx b/src/components/Explore.tsx index c9a13ca1..b02e81dd 100644 --- a/src/components/Explore.tsx +++ b/src/components/Explore.tsx @@ -68,13 +68,14 @@ const Explore: React.FC = ({ relayPool, eventStore, settings, acti setLoading(true) // Seed from in-memory cache if available to avoid empty flash + // Use functional update to check current state without creating dependency const cachedPosts = getCachedPosts(activeAccount.pubkey) - if (cachedPosts && cachedPosts.length > 0 && blogPosts.length === 0) { - setBlogPosts(cachedPosts) + if (cachedPosts && cachedPosts.length > 0) { + setBlogPosts(prev => prev.length === 0 ? cachedPosts : prev) } const cachedHighlights = getCachedHighlights(activeAccount.pubkey) - if (cachedHighlights && cachedHighlights.length > 0 && highlights.length === 0) { - setHighlights(cachedHighlights) + if (cachedHighlights && cachedHighlights.length > 0) { + setHighlights(prev => prev.length === 0 ? cachedHighlights : prev) } // Fetch the user's contacts (friends) @@ -210,8 +211,6 @@ const Explore: React.FC = ({ relayPool, eventStore, settings, acti } loadData() - // Note: intentionally not including blogPosts/highlights length to avoid re-fetch loops - // eslint-disable-next-line react-hooks/exhaustive-deps }, [relayPool, activeAccount, refreshTrigger, eventStore, settings]) // Pull-to-refresh