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.

Join the community!

Join our discord server! You can click the floating discord icon at the bottom right of the screen and chat with us!

Powered by vercel