Skip to content

Instantly share code, notes, and snippets.

View awran5's full-sized avatar
🎯
Focusing

Ahmed Khalil awran5

🎯
Focusing
View GitHub Profile
@awran5
awran5 / interval.hook.ts
Created October 31, 2020 21:28 — forked from Danziger/interval.hook.ts
✨ Declarative useTimeout (setTimeout), useInterval (setInterval) and useThrottledCallback (useCallback combined with setTimeout) hooks for React (in Typescript)
import React, { useEffect, useRef } from 'react';
/**
* Use setInterval with Hooks in a declarative way.
*
* @see https://stackoverflow.com/a/59274004/3723993
* @see https://overreacted.io/making-setinterval-declarative-with-react-hooks/
*/
export function useInterval(
callback: React.EffectCallback,