
Security News
Deno 2.4 Brings Back deno bundle, Improves Dependency Management and Observability
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
react-countdown-circle-timer
Advanced tools
Lightweight React countdown timer component with color and progress animation based on SVG
React countdown timer component in a circle shape with color and progress animation.
requestAnimationFrame
loop to animate color and progress (no setInterval
used)a11y
supportyarn add react-countdown-circle-timer
There are a few small API changes to consider before switching to v2.x.x. Read Migrate to v2.x.x docs for more info.
Check the demo on CodeSandbox to get started
import { CountdownCircleTimer } from 'react-countdown-circle-timer'
const UrgeWithPleasureComponent = () => (
<CountdownCircleTimer
isPlaying
duration={10}
colors={[['#004777', 0.33], ['#F7B801', 0.33], ['#A30000']]}
>
{({ remainingTime }) => remainingTime}
</CountdownCircleTimer>
)
Refer to the list of props
Pass a key
prop to CountdownCircleTimer
and change the key
when the timer should be restarted.
Return an array from onComplete
handler, which indicates if the animation should be repeated. Example:
const UrgeWithPleasureComponent = () => (
<CountdownCircleTimer
onComplete={() => {
// do your stuff here
return [true, 1500] // repeat animation in 1.5 seconds
}}
isPlaying
duration={10}
colors={[['#A30000']]}
/>
)
Pass the remaining time to initialRemainingTime
prop. Example:
const UrgeWithPleasureComponent = () => (
<CountdownCircleTimer
isPlaying
duration={60}
initialRemainingTime={15}
colors={[['#A30000']]}
/>
)
In the example above, the countdown will start at 15 seconds (one quarter before it's done) and it will animate for 15 seconds until reaches 0.
Here is an example on how you can achieve the animation below:
const renderTime = (time) => {
const currentTime = useRef(time)
const prevTime = useRef(null)
const isNewTimeFirstTick = useRef(false)
const [_, setOneLastRerender] = useState(0)
if (currentTime.current !== time) {
isNewTimeFirstTick.current = true
prevTime.current = currentTime.current
currentTime.current = time
} else {
isNewTimeFirstTick.current = false
}
// force one last re-render when the time is over to tirgger the last animation
if (time === 0) {
setTimeout(() => {
setOneLastRerender((val) => val + 1)
}, 20)
}
const isTimeUp = isNewTimeFirstTick.current
return (
<div className="time-wrapper">
<div key={time} className={`time ${isTimeUp ? 'up' : ''}`}>
{time}
</div>
{prevTime.current !== null && (
<div
key={prevTime.current}
className={`time ${!isTimeUp ? 'down' : ''}`}
>
{prevTime.current}
</div>
)}
</div>
)
}
.time-wrapper {
position: relative;
// change width and height if needed
width: 80px;
height: 60px;
}
.time-wrapper .time {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
transform: translateY(0);
opacity: 1;
transition: all 0.2s;
}
.time-wrapper .time.up {
opacity: 0;
transform: translateY(-100%);
}
.time-wrapper .time.down {
opacity: 0;
transform: translateY(100%);
}
Feed the renderTime
function above to the CountdownCircleTimer
children
prop and add the styles above to your stylesheet.
FAQs
Lightweight React countdown timer component with color and progress animation based on SVG
The npm package react-countdown-circle-timer receives a total of 29,631 weekly downloads. As such, react-countdown-circle-timer popularity was classified as popular.
We found that react-countdown-circle-timer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.