-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: useLayoutEffect로 실행하던 스크롤 이동 로직 refCallback으로 변경
- Loading branch information
1 parent
4bf1262
commit c7f3337
Showing
2 changed files
with
9 additions
and
8 deletions.
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 |
---|---|---|
@@ -1,22 +1,23 @@ | ||
import { useLayoutEffect, useRef } from 'react'; | ||
import { useCallback } from 'react'; | ||
import useFetch from '@/shared/hooks/useFetch'; | ||
import useValidParams from '@/shared/hooks/useValidParams'; | ||
import { getSongDetailEntries } from '../remotes/songs'; | ||
import type { Genre } from '../types/Song.type'; | ||
|
||
const useSongDetailEntries = () => { | ||
const { id: songIdParams, genre: genreParams } = useValidParams(); | ||
const currentSongDetailItemRef = useRef<HTMLDivElement>(null); | ||
|
||
const { data: songDetailEntries } = useFetch(() => | ||
getSongDetailEntries(Number(songIdParams), genreParams as Genre) | ||
); | ||
|
||
useLayoutEffect(() => { | ||
currentSongDetailItemRef.current?.scrollIntoView({ behavior: 'instant', block: 'start' }); | ||
}, [songDetailEntries]); | ||
const scrollIntoCurrentSong: React.RefCallback<HTMLDivElement> = useCallback((dom) => { | ||
if (dom === null) return; | ||
|
||
return { songDetailEntries, currentSongDetailItemRef }; | ||
dom.scrollIntoView({ behavior: 'instant', block: 'start' }); | ||
}, []); | ||
|
||
return { songDetailEntries, scrollIntoCurrentSong }; | ||
}; | ||
|
||
export default useSongDetailEntries; |
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