Rooks

useOnWindowResize

About

A React hook for adding an event listener for window resize

Examples

import "./styles.css";
import { useOnWindowResize } from "rooks";
 
export default function App() {
  useOnWindowResize(() => console.log("window resized"));
 
  return (
    <div className="App">
      <h1>useOnWindowResize example</h1>
      <h2>Resize the window and see the logs</h2>
    </div>
  );
}

Arguments

ArgumentsTypeDescriptionDefault value
callbackfunctionCallback function which needs to run on unmountundefined
whenbooleanWhen the event handler should be activetrue
isLayoutEffectbooleanShould it use layout effect.false

Returns

No return value.

On this page