A lightweight React hook to listen for window resize events and get the current window width.
Install the package using npm or yarn:
npm install react-resize-listener-hook
# or
yarn add react-resize-listener-hook
This package provides a useResizeListener
hook that you can use to track the window's width dynamically.
import React from "react";
import { useResizeListener } from "react-resize-listener-hook";
const App = () => {
const { width } = useResizeListener();
return (
<div>
<h1>Window Width: {width}px</h1>
</div>
);
};
export default App;
Returns an object containing the current width of the window.
Key | Type | Description |
---|---|---|
width | number | The current window width. |
- Automatically updates on window resize.
- Lightweight and easy to use.
- Cleanly manages event listeners.
This project is licensed under the MIT License.
Feel free to submit issues or pull requests to improve the package. Contributions are always welcome!