I want to create a function that return setTimeout as a callback to call it programmatically and a clearTimeout as a callback to cancel the setTimeout before it executes the internal callback if necessary, is it possible?
function useDelay(cb: () => void, delay: number) {
const timer = () => setTimeout(cb, delay);
const clearTimer = () => clearTimeout(timer());
return [timer, clearTimer];
}