Skip to content

Commit

Permalink
feat: 블록 애니메이션 hook 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
pipisebastian committed Nov 20, 2024
1 parent 75a2d73 commit 9ee890e
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions client/src/features/editor/hooks/useBlockAnimtaion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useEffect, useState } from "react";

export const useBlockAnimation = (blockRef: React.RefObject<HTMLDivElement>) => {
const [isAnimationStart, setIsAnimationStart] = useState(false);

useEffect(() => {
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
setIsAnimationStart(true);
observer.unobserve(entry.target);
}
});
},
{
threshold: 0.1,
},
);

if (blockRef.current) {
observer.observe(blockRef.current);
}

return () => {
if (blockRef.current) {
observer.unobserve(blockRef.current);
}
};
}, []);

return { isAnimationStart };
};

0 comments on commit 9ee890e

Please sign in to comment.