refactor: clean some codes

This commit is contained in:
rusconn
2024-03-28 12:33:14 +09:00
parent 749c79c8e4
commit 2fc9b7e419
10 changed files with 39 additions and 42 deletions

23
hooks/useAutoScroll.ts Normal file
View File

@@ -0,0 +1,23 @@
import { DependencyList, useEffect, useRef } from "react";
export const useAutoScroll = <T extends HTMLElement = HTMLElement>(
deps: DependencyList,
behavior: ScrollBehavior = "smooth"
) => {
const ref = useRef<T>(null);
useEffect(() => {
const { current } = ref;
if (current) {
current.scrollTo({
left: current.scrollWidth,
top: current.scrollHeight,
behavior,
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, deps);
return ref;
};