Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To correct github star numbers #2

Closed
wants to merge 9 commits into from
13 changes: 5 additions & 8 deletions components/utils/countingNumbers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ export default function CountingNumbers({
interval?: number;
duration?: number;
}) {

const [top, setTop] = useState<boolean>(true);
const [starsCount, setStarsCount] = useState<number>(3000);
const [number, setNumber] = useState(start);


// detect whether user has scrolled the page down by 10px
const scrollHandler = () => {
window.pageYOffset > 10 ? setTop(false) : setTop(true);
Expand Down Expand Up @@ -57,8 +55,9 @@ export default function CountingNumbers({
fetchStarsCount();
}, [starsCount]); // Include starsCount as a dependency


let increment = Math.floor(Math.abs(start - starsCount) / (duration / interval));
let increment = Math.floor(
Math.abs(start - starsCount) / (duration / interval)
);
if (increment === 0) {
increment = 1;
}
Expand Down Expand Up @@ -99,11 +98,9 @@ export default function CountingNumbers({
}
}, [isInView]);



return (
<p className={className} ref={ref}>
{Intl.NumberFormat().format(number)}
{Intl.NumberFormat().format(starsCount)}
</p>
);
}
}