mirror of
https://github.com/Lapikud/tipilan.git
synced 2026-05-08 10:00:46 +00:00
maybe fix the useCountUp hook
This commit is contained in:
@@ -3,13 +3,11 @@
|
|||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
interface UseCountUpOptions {
|
interface UseCountUpOptions {
|
||||||
end: number;
|
end: number;
|
||||||
duration?: number;
|
duration?: number;
|
||||||
suffix?: string;
|
|
||||||
prefix?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useCountUp({ end, duration = 2000, suffix = "", prefix = "" }: UseCountUpOptions) {
|
export function useCountUp({ end, duration = 2000 }: UseCountUpOptions): { ref: React.RefObject<HTMLElement | null>; count: number } {
|
||||||
const [count, setCount] = useState(0);
|
const [count, setCount] = useState(0);
|
||||||
const [hasStarted, setHasStarted] = useState(false);
|
const [hasStarted, setHasStarted] = useState(false);
|
||||||
const ref = useRef<HTMLElement>(null);
|
const ref = useRef<HTMLElement>(null);
|
||||||
@@ -51,7 +49,5 @@ export function useCountUp({ end, duration = 2000, suffix = "", prefix = "" }: U
|
|||||||
requestAnimationFrame(animate);
|
requestAnimationFrame(animate);
|
||||||
}, [hasStarted, end, duration]);
|
}, [hasStarted, end, duration]);
|
||||||
|
|
||||||
const display = `${prefix}${count}${suffix}`;
|
return { ref, count };
|
||||||
|
|
||||||
return { ref, display, count };
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user