Skip to content

A lightweight React hook to listen for window resize events and get the current window width.

Notifications You must be signed in to change notification settings

yashk2023/react-resize-listener-hook

Repository files navigation

react-resize-listener-hook

A lightweight React hook to listen for window resize events and get the current window width.

Installation

Install the package using npm or yarn:

npm install react-resize-listener-hook
# or
yarn add react-resize-listener-hook

Usage

This package provides a useResizeListener hook that you can use to track the window's width dynamically.

Example

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;

API

useResizeListener()

Returns an object containing the current width of the window.

Returns

Key Type Description
width number The current window width.

Features

  • Automatically updates on window resize.
  • Lightweight and easy to use.
  • Cleanly manages event listeners.

License

This project is licensed under the MIT License.

Contributing

Feel free to submit issues or pull requests to improve the package. Contributions are always welcome!

About

A lightweight React hook to listen for window resize events and get the current window width.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published