Skip to content

Instantly share code, notes, and snippets.

View officialdavidtaylor's full-sized avatar

David Taylor officialdavidtaylor

View GitHub Profile
@officialdavidtaylor
officialdavidtaylor / useCurrentTime.ts
Created April 17, 2024 14:50
A React Custom Hook to opt the component (and all downstream components) into re-renders that occur on a specified interval.
import { useRef, useState } from 'react';
/**
* This hook will opt your component (and all downstream components) into
* rerenders that occur on the interval specified.
*
* ⚠️ This may induce serious performance consequences, especially when
* choosing a shorter intervalDuration
*
* @param intervalDuration number (in ms), default to 1000ms