mirror of
https://github.com/drawdb-io/drawdb.git
synced 2025-05-24 10:29:11 +00:00
30 lines
704 B
JavaScript
30 lines
704 B
JavaScript
import { useRef, useEffect } from "react";
|
|
import { motion, useInView, useAnimation } from "framer-motion";
|
|
|
|
export default function FadeIn({ children, duration }) {
|
|
const ref = useRef(null);
|
|
const isInView = useInView(ref, { once: true });
|
|
const mainControls = useAnimation();
|
|
|
|
useEffect(() => {
|
|
if (isInView) {
|
|
mainControls.start("visible");
|
|
}
|
|
}, [isInView, mainControls]);
|
|
|
|
return (
|
|
<div ref={ref}>
|
|
<motion.div
|
|
variants={{
|
|
hidden: { opacity: 0 },
|
|
visible: { opacity: 1 },
|
|
}}
|
|
initial="hidden"
|
|
animate={mainControls}
|
|
transition={{ duration }}
|
|
>
|
|
{children}
|
|
</motion.div>
|
|
</div>
|
|
);
|
|
} |