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

0.8.0 • Public • Published

React Performance Hooks

NPM npm bundle size npm type definitions NPM npm GitHub stars

Debounce and throttle your functions to gain performance boost!

Features

  • 🚀 Simple, fast and light
  • 🏭 Debounce and Throttle
  • 🪗 Lifecycle events handling

Install

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

or

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

useDebounce

This hook allows debouncing of the given function.

import React from "react";
import { useDebounce } from "@better-typed/react-performance-hooks";

const MyComponent: React.FC = ({ delay }) => {
  const {debounce, reset, active} = useDebounce(delay)

  // Standard usage
  const onTyping = () => {
    debounce(() => {
      // debounced logic
    })
  }

  // Dynamic delay value
  const onTypingDynamic = (value: string, customDelay: number) => {
    debounce(() => {
      // debounced logic
    }, customDelay)
  }

  return (
    // ...
  )
}

useThrottle

This hook allows debouncing of the given function.

import React from "react";
import { useThrottle } from "@better-typed/react-performance-hooks";

const MyComponent: React.FC = ({ delay }) => {
  const {throttle, reset, active} = useThrottle(delay)

  // Standard usage
  const onScroll = () => {
    throttle(() => {
      // throttle logic
    })
  }

  // Dynamic delay value
  const onScrollDynamic = (value: string, customDelay: number) => {
    throttle(() => {
      // throttle logic
    }, customDelay)
  }

  return (
    // ...
  )
}

/@better-typed/react-performance-hooks/

    Package Sidebar

    Install

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

    Weekly Downloads

    557

    Version

    0.8.0

    License

    MIT

    Unpacked Size

    8.96 kB

    Total Files

    11

    Last publish

    Collaborators

    • geras_nyx
    • albelew
    • prc5