Skip to content

Instantly share code, notes, and snippets.

View BrentonHolloway's full-sized avatar

Brenton Holloway BrentonHolloway

  • ThinkSmart Health Pty Ltd
  • Rockhampton, QLD, Australia
  • 04:24 (UTC +10:00)
  • LinkedIn in/brenton-holloway
View GitHub Profile
@BrentonHolloway
BrentonHolloway / Clock.jsx
Last active January 11, 2021 06:10
React Clock using moment
import React, { useState, useEffect, useRef } from 'react'
import moment form 'moment'
function Clock() {
const [time, setTime] = useState(moment())
const intervalRef = useRef()
useEffect(() => {
intervalRef.current = setTimeout(() => {
setTime(prevTime => prevTime.clone().add(1, 'second'))