Skip to content

Commit

Permalink
use useInterval
Browse files Browse the repository at this point in the history
  • Loading branch information
JFrankfurt committed Nov 12, 2021
1 parent f7a3f4a commit 9c39804
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/hooks/useMachineTime.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { useEffect, useState } from 'react'
import { useState } from 'react'

import useInterval from './useInterval'

const useMachineTimeMs = (updateInterval: number): number => {
const [now, setNow] = useState(Date.now())

useEffect(() => {
const timer = setInterval(() => {
setNow(Date.now())
}, updateInterval)
return () => {
clearInterval(timer)
}
}, [updateInterval])
useInterval(() => {
setNow(Date.now())
}, updateInterval)
return now
}

Expand Down

0 comments on commit 9c39804

Please sign in to comment.