I have the following hook using useLayoutEffect
to register an event listener on the resize event of the window.
I would like to add a throttle to it, say 1000ms, to call handleCanvasResize
at most once per second.
What syntax should I use ?
useLayoutEffect(() => {
window.addEventListener('resize', handleCanvasResize);
return () => {
window.removeEventListener('resize', handleCanvasResize);
};
}, [handleCanvasResize]);
question from:https://stackoverflow.com/questions/65940908/react-hooks-throttle-on-uselayouteffect