-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathcountingNumbers.tsx
45 lines (38 loc) · 1.06 KB
/
countingNumbers.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"use client";
import { useEffect, useState } from "react";
const formatStars = (num: number) =>
Intl.NumberFormat('en-US', {
notation: "compact",
maximumFractionDigits: 1,
}).format(num);
interface CountingNumbersProps {
className: string;
reverse?: boolean;
start?: number;
interval?: number;
duration?: number;
}
export default function CountingNumbers({
className,
}: CountingNumbersProps) {
const [starsCount, setStarsCount] = useState<number>(0);
useEffect(() => {
const fetchStarsCount = async () => {
try {
const response = await fetch(
"https://api.github.com/repos/keploy/keploy"
);
if (response.ok) {
const data = await response.json();
setStarsCount(data.stargazers_count);
} else {
console.error("Failed to fetch stars count", response.statusText);
}
} catch (error) {
console.error("Error fetching stars count:", error);
}
};
fetchStarsCount();
}, []);
return <p className={className}>{formatStars(starsCount)}</p>;
}