Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FE] refactor: scrollTop에서 ref로 접근하는 방식으로 변경 #639

Merged
merged 13 commits into from
Sep 15, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions frontend/src/hooks/common/useScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import type { RefObject } from 'react';

const useScroll = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

훅의 인자로 ref를 받는건 어떤가요??

const scrollToTop = <T extends HTMLElement>(ref: RefObject<T>) => {
if (!ref.current) {
return;
if (ref.current) {
ref.current.scrollTo(0, 0);
}

ref.current?.scrollTo(0, 0);
};

const scrollToPosition = <T extends HTMLElement>(ref: RefObject<T>) => {
setTimeout(() => {
ref.current?.scrollIntoView({ behavior: 'smooth' });
}, 100);
if (ref.current) {
const timeout = setTimeout(() => {
ref.current?.scrollIntoView({ behavior: 'smooth' });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? 삭제해주세요 ㅎㅎ 제가 안 지웠음 ㅎㅎㅎ..

clearTimeout(timeout);
}, 100);
}
};

return { scrollToTop, scrollToPosition };
Expand Down