From 60a92605dcd85096db0228517fcbe6126afcea18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Saracca?= Date: Fri, 19 Jul 2024 11:49:14 -0300 Subject: [PATCH] feat: scroll to top on page render --- src/sections/collection/Collection.tsx | 2 ++ src/shared/hooks/useScrollTop.ts | 7 +++++++ 2 files changed, 9 insertions(+) create mode 100644 src/shared/hooks/useScrollTop.ts diff --git a/src/sections/collection/Collection.tsx b/src/sections/collection/Collection.tsx index cef5ea5e9..282388dac 100644 --- a/src/sections/collection/Collection.tsx +++ b/src/sections/collection/Collection.tsx @@ -13,6 +13,7 @@ import { PageNotFound } from '../page-not-found/PageNotFound' import { CollectionSkeleton } from './CollectionSkeleton' import { CollectionInfo } from './CollectionInfo' import { Trans, useTranslation } from 'react-i18next' +import { useScrollTop } from '../../shared/hooks/useScrollTop' interface CollectionProps { repository: CollectionRepository @@ -31,6 +32,7 @@ export function Collection({ page, infiniteScrollEnabled = false }: CollectionProps) { + useScrollTop() const { user } = useSession() const { collection, isLoading } = useCollection(repository, id) const { t } = useTranslation('collection') diff --git a/src/shared/hooks/useScrollTop.ts b/src/shared/hooks/useScrollTop.ts new file mode 100644 index 000000000..9c5494140 --- /dev/null +++ b/src/shared/hooks/useScrollTop.ts @@ -0,0 +1,7 @@ +import { useEffect } from 'react' + +export const useScrollTop = () => { + useEffect(() => { + window.scrollTo({ top: 0, behavior: 'smooth' }) + }, []) +}