From 35e709de7d3300c2de0b9158d098b10ef185d6ca Mon Sep 17 00:00:00 2001 From: Pratyush Kongalla <44525862+pratyush3124@users.noreply.github.com> Date: Sat, 6 Jul 2024 13:36:30 +0530 Subject: [PATCH] fix(navbar): shouldHideOnScroll fixed (#3315) * fix(navbar): shouldHideOnScroll fixed * Update packages/hooks/use-scroll-position/src/index.ts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update index.ts * fix(navbar): applying suggested changes --------- Co-authored-by: Pratyush Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .changeset/happy-cameras-whisper.md | 5 +++++ packages/hooks/use-scroll-position/src/index.ts | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .changeset/happy-cameras-whisper.md diff --git a/.changeset/happy-cameras-whisper.md b/.changeset/happy-cameras-whisper.md new file mode 100644 index 0000000000..5b720ad7bf --- /dev/null +++ b/.changeset/happy-cameras-whisper.md @@ -0,0 +1,5 @@ +--- +"@nextui-org/use-scroll-position": patch +--- + +clearing throttleTimeout when it is supposed to be null in useScrollPosition (#3139) diff --git a/packages/hooks/use-scroll-position/src/index.ts b/packages/hooks/use-scroll-position/src/index.ts index 8a85280829..74a57ed6aa 100644 --- a/packages/hooks/use-scroll-position/src/index.ts +++ b/packages/hooks/use-scroll-position/src/index.ts @@ -59,9 +59,11 @@ export const useScrollPosition = (props: UseScrollPositionOptions): ScrollValue const handleScroll = () => { if (delay) { - if (throttleTimeout.current === null) { - throttleTimeout.current = setTimeout(handler, delay); + if (throttleTimeout.current) { + clearTimeout(throttleTimeout.current); } + + throttleTimeout.current = setTimeout(handler, delay); } else { handler(); }