Skip to content

Commit c811934

Browse files
committed
feat: add useAnimateScroll hook
1 parent 6d13744 commit c811934

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

modules/hooks/useAnimateScroll.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { useEffect, useRef } from "react";
2+
3+
const useAnimateScroll = ({ method, options }) => {
4+
if (!method) {
5+
throw new Error("You need to provide a animateScroll method");
6+
}
7+
8+
const containerRef = useRef();
9+
10+
useEffect(() => {
11+
if (containerRef && containerRef.current) {
12+
method({
13+
container: containerRef.current,
14+
...options,
15+
});
16+
}
17+
}, [
18+
containerRef,
19+
method,
20+
options,
21+
]);
22+
23+
return containerRef;
24+
};
25+
26+
export default useAnimateScroll;

0 commit comments

Comments
 (0)