Skip to content

Commit 1ebed6e

Browse files
committed
fix: optimize the stats as code rabbit suggested
1 parent 2feef38 commit 1ebed6e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/components/sections/homepage/_partials/testimonials/CommunityStats.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Button from "@/components/ui/button";
22
import DiscordIcon from "@/icons/discord.svg";
33
import { useTranslation } from "next-i18next";
4+
import { useMemo } from "react";
45

56
/**
67
* Statistic interface definitions
@@ -33,15 +34,24 @@ const stats: Statistic[] = [
3334
];
3435
export default function CommunityStats() {
3536
const { t } = useTranslation();
36-
const digitFormatter = new Intl.NumberFormat();
37+
const digitFormatter = useMemo(() => new Intl.NumberFormat(), []);
38+
39+
const formattedStat = useMemo(
40+
() =>
41+
stats.map((stat: Statistic) => ({
42+
...stat,
43+
count: digitFormatter.format(stat.count),
44+
})),
45+
[digitFormatter]
46+
);
3747

3848
return (
3949
<div className="p-7 bg-primary rounded-3.5xl mx-auto text-white relative md:absolute md:top-28 lg:top-32 xl:w-1/3 md:w-4/6 z-10 sm:max-w-sm">
4050
<h3 className="m-0 text-4.5xl w-3/4">{t("testimonials.community.title")}</h3>
4151
<div className="relative divide-y divide-white divide-dotted">
42-
{stats.map((stat) => (
52+
{formattedStat.map((stat) => (
4353
<div key={stat.title} className="py-6">
44-
<span className="block text-.5xl mb-2">{digitFormatter.format(stat.count)}</span>
54+
<span className="block text-.5xl mb-2">{stat.count}</span>
4555
<p className="text-base w-3/4 m-0">
4656
<span className="font-graphik font-medium">{t(stat.title)}</span> {t(stat.description)}
4757
</p>

0 commit comments

Comments
 (0)