[useScrollTo, useScrollToTop] - useScrollTo: animate 효과 제어 기능 추가

- useScrollToTop: scrollToTop 기능 추가 및 hook 분리
This commit is contained in:
hyunwoo93.cha
2024-02-20 16:34:27 +09:00
parent 58058f6f67
commit 2bdb40d606
3 changed files with 34 additions and 5 deletions

View File

@@ -3,15 +3,15 @@ import React, { useCallback, useEffect, useRef } from "react";
export default function useScrollTo() {
const scrollTo = useRef();
const scrollTop = useCallback(() => {
const scrollTop = useCallback(({ animate = true } = {}) => {
if (scrollTo && scrollTo.current) {
scrollTo.current({ position: { y: 0 }, animate: true });
scrollTo.current({ position: { y: 0 }, animate: animate });
}
}, []);
const scrollLeft = useCallback(() => {
const scrollLeft = useCallback(({ animate = false } = {}) => {
if (scrollTo && scrollTo.current) {
scrollTo.current({ position: { x: 0 }, animate: false });
scrollTo.current({ position: { x: 0 }, animate: animate });
}
}, []);