Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/CompanyTrustedList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function CompanyList() {
<CountUp
value={21500}
durationMs={1500}
format={(n) => `${n.toLocaleString()}+`}
format={(n) => `${n.toLocaleString('en-US')}+`}
/>{' '}
Developers at Companies Like:
</h2>
Expand Down
19 changes: 11 additions & 8 deletions src/components/CountUp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@ import { useEffect, useRef, useState } from 'react'
// into view. Eases out (cubic) so the count slows toward the final
// number rather than stopping abruptly.
//
// The server-rendered HTML (and the first client render) already contains
// the final `value`, so crawlers and tools that do not run JavaScript read
// the real number. The count only restarts from 0 in the browser when the
// element scrolls into view.
//
// `format` is called with the current number to render the displayed
// string (e.g. add a "+" or commas). Defaults to localized integer.
//
// Honors `prefers-reduced-motion` — renders the final number
// immediately with no animation.
// Honors `prefers-reduced-motion` — keeps the final number with no
// animation.
export function CountUp({ value, durationMs = 1500, format }) {
const ref = useRef(null)
const [n, setN] = useState(0)
const formatFn = format || ((x) => x.toLocaleString())
const [n, setN] = useState(value)
const formatFn = format || ((x) => x.toLocaleString('en-US'))

useEffect(() => {
if (typeof window === 'undefined') return
const reduce = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
if (reduce) {
setN(value)
return
}
if (reduce) return
const node = ref.current
if (!node) return
let raf = 0
Expand All @@ -42,6 +44,7 @@ export function CountUp({ value, durationMs = 1500, format }) {
([entry]) => {
if (entry.isIntersecting && !started) {
started = true
setN(0)
start(performance.now())
obs.unobserve(node)
}
Expand Down