Skip to content

Instantly share code, notes, and snippets.

View PhilipWee's full-sized avatar

Philip Andrew Wee De Wang PhilipWee

View GitHub Profile
export function Component() {
const meaningOfLife = getTheAnswerToLife(allUniverseData);
return <div>{meaningOfLife}</div>;
}
const timer = useRef<Timer>();
useEffect(() => {
return () => {
if (!timer.current) return;
clearTimeout(timer.current);
};
}, []);
@PhilipWee
PhilipWee / todo.js
Created October 27, 2022 09:05
TODO
//TODO: Update this with clickthrough statistics from this article to FireJet Website
const debouncedFunction = (...args) => {return args}
const finalArgs = debouncedFunction("arg1","arg2","arg3")
//finalArgs === ["arg1","arg2","arg3"]
const _changeText(newText:string) {
setText(newText)
}
const changeText = useDebounce(_changeText, 1000)
.
.
.
function useDebounce<Func extends SomeFunction>(func: Func, delay: number) {
.
.
.
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(() => {
type Timer = ReturnType<typeof setTimeout>;
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);