Skip to content

Commit 0d00c51

Browse files
committed
fix: Update useFetcher to trigger on valid URL and improve cleanup logic
1 parent 19c54c3 commit 0d00c51

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/react/index.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export function useFetcher<
222222
// Load the initial data if not already cached and not currently fetching
223223
if (
224224
shouldTriggerOnMount &&
225-
currentValuesRef.current[0] &&
225+
url &&
226226
!state.data &&
227227
!state.error &&
228228
!state.isFetching
@@ -239,14 +239,9 @@ export function useFetcher<
239239
incrementRef(cacheKey);
240240

241241
return () => {
242-
decrementRef(
243-
cacheKey,
244-
cacheTime,
245-
dedupeTime,
246-
currentValuesRef.current[0],
247-
);
242+
decrementRef(cacheKey, cacheTime, dedupeTime, url);
248243
};
249-
}, [shouldTriggerOnMount, cacheKey, cacheTime]);
244+
}, [url, shouldTriggerOnMount, cacheKey, cacheTime]);
250245

251246
const mutate = useCallback<
252247
UseFetcherResult<

0 commit comments

Comments
 (0)