Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
6 replies
harshcut

is this the correct use of usecallback?

  const foo = React.useCallback(() => {
    const clientDate = new Date()
    const utcDate = clientDate.getTime() + clientDate.getTimezoneOffset() * 60000
    const timeOffset = 5.5
    const localDate = new Date(utcDate + 3600000 * timeOffset)
    setDate(localDate)
  }, [])

  React.useEffect(() => {
    foo()
    const timer = setInterval(() => foo(), 1000)
    return () => {
      clearInterval(timer)
    }
  }, [foo])
Was this page helpful?