Let's say I have some code like this:
const X = useRef<boolean(false)
const setX = (value: boolean) => {
if (value) {
window.setTimeout(() => {
X.current = false;
}, 1000);
X.current = value
}
So that when I call setX(true), X is only true for one second.
I have a bunch of these repeated in code, and would like to make a hook out of it. Something like:
const [X, setX] = useSetWithDelay(false, 1000)
const [Y, setY] = useSetWithDelay(false, 1000)
...
How can I do that?
Via Active questions tagged javascript - Stack Overflow https://ift.tt/3BGuOmi
Comments
Post a Comment