initial commit, setup
This commit is contained in:
33
hooks/useAnimations.ts
Normal file
33
hooks/useAnimations.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
export function useStaggerReveal(count: number, baseDelay = 80) {
|
||||
const [visible, setVisible] = useState<Set<number>>(new Set());
|
||||
|
||||
useEffect(() => {
|
||||
const timers: ReturnType<typeof setTimeout>[] = [];
|
||||
for (let i = 0; i < count; i++) {
|
||||
timers.push(
|
||||
setTimeout(
|
||||
() => setVisible((prev) => new Set(prev).add(i)),
|
||||
baseDelay * (i + 1) + 200
|
||||
)
|
||||
);
|
||||
}
|
||||
return () => timers.forEach(clearTimeout);
|
||||
}, [count, baseDelay]);
|
||||
|
||||
return visible;
|
||||
}
|
||||
|
||||
export function useMountTransition(delay = 50) {
|
||||
const [mounted, setMounted] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const t = setTimeout(() => setMounted(true), delay);
|
||||
return () => clearTimeout(t);
|
||||
}, [delay]);
|
||||
|
||||
return mounted;
|
||||
}
|
||||
Reference in New Issue
Block a user