Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
1import { useDebounce } from "@uidotdev/usehooks";
2import { useCallback, useEffect, useState } from "react";
3
4const useDebouncedCallback = (callback: VoidFunction, delay: number) => {
5 const [changeSignal, setChangeSignal] = useState(-1);
6 const debouncedChangeSignal = useDebounce(changeSignal, delay);
7
8 const increaseChanges = useCallback(() => {
9 setChangeSignal((num) => (num + 1) % Number.MAX_SAFE_INTEGER);
10 }, []);
11
12 useEffect(() => {
13 if (debouncedChangeSignal >= 0) {
14 callback();
15 }
16 }, [debouncedChangeSignal, callback]);
17
18 return increaseChanges;
19};
20
21export default useDebouncedCallback;