use-seconds
v1.7.0
Published
Seconds interval time for React
Downloads
140
Readme
use-seconds
Seconds interval time for React
this timer is Keep adjusting setTimeout
timing and return adjusted Time.
round(01:00:53.011Z) => 01:00:53.000Z
round(01:00:53.998Z) => 01:00:54.000Z
DEMO use-seconds-example - CodeSandbox
Install
npm install --save use-seconds
Usage
import * as React from "react"
import { useSeconds } from "use-seconds"
const Example = () => {
const [time, eventTime, nextMs] = useSeconds() // Date object
return (
<div>
<p>{time.toISOString()}</p>
<p>{eventTime.toISOString()}</p>
<p>{next}</p>
{/*
2023-05-24T01:12:53.000Z
2023-05-24T01:12:53.011Z
989
*/}
</div>
)
}
Rounding Time
10.995 s → return 11.000 s
↓ setTimeout 1005 (ms)
12.003 s → return 12.000 s
↓ setTimeout 997 (ms)
License
MIT © elzup
This hook is created using create-react-hook.