
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
react-timer-hook
Advanced tools
React timer hook is a custom react hook built to handle timers and count down logic in your react component.
React timer hook is a custom react hook, built to handle timers and countdown logic in your react component.
React hooks is available from react version 16.8.0
yarn add react-timer-hook
OR
npm install --save react-timer-hook
import React from 'react';
import useTimer from 'react-timer-hook';
export default function App() {
const {
seconds,
minutes,
hours,
days,
startTimer,
stopTimer,
resetTimer,
} = useTimer({ autoStart: true });
return (
<div style={{textAlign: 'center'}}>
<h1>react-timer-hook Demo</h1>
<div style={{fontSize: '100px'}}>
<span>{days}</span>:<span>{hours}</span>:<span>{minutes}</span>:<span>{seconds}</span>
</div>
<button onClick={startTimer}>Start</button>
<button onClick={stopTimer}>Stop</button>
<button onClick={resetTimer}>Reset</button>
</div>
);
}
key | Type | Required | Description |
---|---|---|---|
autoStart | boolean | No | if set to true timer will auto start |
expiryTimestamp | number(timestamp) | No | if set a countdown timer will start, instead of normal timer |
onExpire | Function | No | callback function to be executed once countdown timer is expired, works only for countdown |
key | Type | Description |
---|---|---|
seconds | number | seconds value |
minutes | number | minutes value |
hours | number | hours value |
days | number | days value |
startTimer | function | function to be called to start timer |
stopTimer | function | function to be called to stop timer |
resetTimer | function | function to be called to reset timer, this reset will not make sense with countdown timer |
FAQs
React timer hook is a custom react hook built to handle timers(countdown), stopwatch and time logic/state in your react component.
The npm package react-timer-hook receives a total of 86,391 weekly downloads. As such, react-timer-hook popularity was classified as popular.
We found that react-timer-hook demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.