use-seconds
TypeScript icon, indicating that this package has built-in type declarations

1.7.0 • Public • Published

use-seconds

NPM JavaScript Style Guide

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.

Package Sidebar

Install

npm i use-seconds

Weekly Downloads

18

Version

1.7.0

License

MIT

Unpacked Size

10.1 kB

Total Files

12

Last publish

Collaborators

  • elzup