From 1dab0a56b44992d0d8b091b296f7e28ab1be46ce Mon Sep 17 00:00:00 2001 From: Nam Nguyen Date: Fri, 21 Jul 2023 18:48:26 +0700 Subject: [PATCH] fix: arrow scroll down menu (#2100) --- src/components/Menu/index.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/components/Menu/index.tsx b/src/components/Menu/index.tsx index 4d1383051a..ef7cabfe5f 100644 --- a/src/components/Menu/index.tsx +++ b/src/components/Menu/index.tsx @@ -1,5 +1,5 @@ import { Trans, t } from '@lingui/macro' -import { useEffect, useRef, useState } from 'react' +import { useEffect, useState } from 'react' import { isMobile } from 'react-device-detect' import { Award, @@ -266,28 +266,27 @@ export default function Menu() { mixpanelHandler(MIXPANEL_TYPE.MENU_PREFERENCE_CLICK, { menu: name }) } - const wrapperNode = useRef(null) + const [wrapperNode, setWrapperNode] = useState(null) const [showScroll, setShowScroll] = useState(false) useEffect(() => { - const wrapper = wrapperNode.current - if (wrapper) { + if (wrapperNode) { const abortController = new AbortController() const onScroll = () => { if (abortController.signal.aborted) return - setShowScroll(Math.abs(wrapper.offsetHeight + wrapper.scrollTop - wrapper.scrollHeight) > 10) //no need to show scroll down when scrolled to last 10px + setShowScroll(Math.abs(wrapperNode.offsetHeight + wrapperNode.scrollTop - wrapperNode.scrollHeight) > 10) //no need to show scroll down when scrolled to last 10px } onScroll() - wrapper.addEventListener('scroll', onScroll) + wrapperNode.addEventListener('scroll', onScroll) window.addEventListener('resize', onScroll) return () => { abortController.abort() - wrapper.removeEventListener('scroll', onScroll) + wrapperNode.removeEventListener('scroll', onScroll) window.removeEventListener('resize', onScroll) } } return - }, []) + }, [wrapperNode]) return ( @@ -308,7 +307,7 @@ export default function Menu() { ) : ( - + setWrapperNode(wrapperNode)}> <Trans>Menu</Trans>