add throttling operation in the scroll event of Main component - set 150ms, compared with the previous trigger frequency reduced by about 8 times (i.e., to ensure that the user experience has been the same as before at the same time, but also to avoid triggering the scroll event too frequently, to improve the performance of scrolling)
add event cleanup operation, in the current scenario (Main component always exists in the page, listening to events wrapped by useCallback) theoretically do not clean up the event listener will not cause memory leaks or performance problems, but based on the maintenance point of view, add on is still a good practice, to ensure that in any scenario the code is robust
Remove duplicate state settings setOffsetTop(false) Every time a scroll event is triggered, if the scroll height does not change, there is no need to duplicate the state settings.
setOffsetTop(false)
Every time a scroll event is triggered, if the scroll height does not change, there is no need to duplicate the state settings.