-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c6b14f6
refactor: 스크롤 이벤트를 엘리먼트에 접근하지 않고 ref로 접근하게 구현
xodms0309 7a00985
Merge branch 'develop' of https://github.com/woowacourse-teams/2023-f…
xodms0309 884fb3e
feat: 스크롤 버튼 디자인 수정
xodms0309 34fe4f4
feat: 상품 상세 페이지에도 스크롤 적용
xodms0309 218032e
refactor: hook이 최상단에 있게끔 수정
xodms0309 377a993
feat: 마이페이지에서도 스크롤 버튼 추가
xodms0309 a9a5bcf
refactor: scrollTop 함수가 ref를 받도록 수정
xodms0309 70da005
refactor: 스크롤 버튼에서 불필요한 useEffect삭제
xodms0309 7c9d3f8
refactor: useScroll 훅 리팩토링
xodms0309 9ed1212
refactor: useScrollRestoration 훅을 컴포넌트에서 페이지로 이동
xodms0309 e8441fe
refactor: recipeRef를 컴포넌트에서 페이지로 이동
xodms0309 c409ee1
fix: if문 setTimeout 안으로 이동
xodms0309 b8afb18
Merge branch 'develop' of https://github.com/woowacourse-teams/2023-f…
xodms0309 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,18 @@ import type { RefObject } from 'react'; | |
|
||
const useScroll = () => { | ||
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' }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? 삭제해주세요 ㅎㅎ 제가 안 지웠음 ㅎㅎㅎ.. |
||
clearTimeout(timeout); | ||
}, 100); | ||
} | ||
}; | ||
|
||
return { scrollToTop, scrollToPosition }; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
훅의 인자로 ref를 받는건 어떤가요??