This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function Component() { | |
const meaningOfLife = getTheAnswerToLife(allUniverseData); | |
return <div>{meaningOfLife}</div>; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const timer = useRef<Timer>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
useEffect(() => { | |
return () => { | |
if (!timer.current) return; | |
clearTimeout(timer.current); | |
}; | |
}, []); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//TODO: Update this with clickthrough statistics from this article to FireJet Website |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const debouncedFunction = (...args) => {return args} | |
const finalArgs = debouncedFunction("arg1","arg2","arg3") | |
//finalArgs === ["arg1","arg2","arg3"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _changeText(newText:string) { | |
setText(newText) | |
} | |
const changeText = useDebounce(_changeText, 1000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. | |
. | |
. | |
function useDebounce<Func extends SomeFunction>(func: Func, delay: number) { | |
. | |
. | |
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from "react"; | |
type SomeFunction = (...args: any[]) => void; | |
type Timer = ReturnType<typeof setTimeout>; | |
function useDebounce<Func extends SomeFunction>(func: Func, delay) { | |
const [timer, setTimer] = useState<Timer>(); //Create timer state | |
const debouncedFunction = ((...args) => { | |
const newTimer = setTimeout(() => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Timer = ReturnType<typeof setTimeout>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from "react"; | |
type SomeFunction = (...args: any[]) => void; | |
function useDebounce<Func extends SomeFunction>(func: Func, delay) { | |
const [timer, setTimer] = useState(); //Create timer state | |
const debouncedFunction = ((...args) => { | |
const newTimer = setTimeout(() => { | |
func(...args); |
NewerOlder