kandi background
Explore Kits

Resize event in react

by vsasikalabe Updated: Jan 24, 2023

The resize event fires when the document view (window) has been resized. This event is not cancelable and does not bubble. In some earlier browsers it was possible to register resize event handlers on any HTML element.A really common need is to get the current size of the browser window. This hook returns an object containing the window's width and height. If executed server-side (no window object) the value of width and height will be undefined.addEventListener accepts the event type, a listener callback function and an options or useCapture parameter. To remove an event listener in React,Add the event listener in the useEffect hook,Return a function from the useEffect hook and Use the removeEventListener method to remove the event listener when the component unmounts.