@better-typed/react-window-hooks
TypeScript icon, indicating that this package has built-in type declarations

0.9.0 • Public • Published

React Window Hooks

NPM npm bundle size npm type definitions NPM npm GitHub stars

Handle window events and observe window size

Features

  • 🚀 Simple, fast and light
  • 🏭 Observe window size
  • 🪗 Lifecycle window events handling

Install

npm install --save @better-typed/react-window-hooks

or

yarn add @better-typed/react-window-hooks

useWindowEvent

import React from "react";
import { useWindowEvent } from "@better-typed/react-window-hooks";

const MyComponent: React.FC = () => {
  // Unmounts event with component lifecycle
  useWindowEvent("resize", () => {
    // ... Do something
  });

  return (
    // ...
  )
}
import React from "react";
import { useWindowEvent } from "@better-typed/react-window-hooks";

const MyComponent: React.FC = () => {
  // Unmounts event with component lifecycle
  useWindowEvent("scroll", () => {
    // ... Do something
  });

  return (
    // ...
  )
}

useWindowSize

import React from "react";
import { useWindowSize } from "@better-typed/react-window-hooks";

const MyComponent: React.FC = () => {
  // Updates with resizing
  const [width, height] = useWindowSize()

  return (
    // ...
  )
}

Package Sidebar

Install

npm i @better-typed/react-window-hooks

Weekly Downloads

3

Version

0.9.0

License

MIT

Unpacked Size

8.71 kB

Total Files

8

Last publish

Collaborators

  • geras_nyx
  • albelew
  • prc5