Skip to content

Commit

Permalink
Refactored logic to scroll to first row
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhayVAshokan committed Jul 17, 2024
1 parent 213fe17 commit 07d706f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/components/Table/hooks/useRestoreScrollPosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ export const useRestoreScrollPosition = ({ tableRef, scrollRef, loading }) => {

useEffect(() => {
if (loading) {
setScrollPosition(key, 1);
setScrollPosition(key, 0);

return;
}

if (scrollRef.current === null || isNil(scrollPositions[key])) return;

setTimeout(() => scrollRef.current.scrollTo({ top: scrollPositions[key] }));
setTimeout(() => {
const position = scrollPositions[key];
const config = position === 0 ? { index: 0 } : { top: position };
scrollRef.current.scrollTo(config);
});
}, [key, tableRef, loading]);

const handleScroll = useFuncDebounce(event => {
Expand Down

0 comments on commit 07d706f

Please sign in to comment.