Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@react-hook/throttle

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-hook/throttle

A react hook for throttling values and callbacks

  • 1.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
202K
decreased by-7.13%
Maintainers
1
Weekly downloads
 
Created
Source

bundlephobia MIT license


@react-hook/throttle

A react hook for throttling values and callbacks.

Installation

npm i @react-hook/throttle
yarn add @react-hook/throttle

Usage

import {useThrottle, useThrottleCallback} from '@react-hook/throttle'
// throttling a value
const F = props => {
    // basic usage
    const [value, setValue] = useThrottle(
      'initialValue', 
      30/*fps*/, 
      true/*leading*/
    )
}
// throttling a callback
const CallbackExample = (initialState, fps = 30, leading = false) => {
  // this is the exact code that useThrottle() uses
  const [state, setState] = useState(initialState)
  return [
    state, 
    useThrottleCallback(setState, fps, leading)
  ]
}

useThrottle(initialValue: any, fps?: number, leading?: bool)

  • initialValue <any>
    • Sets an initial state
  • fps <number>
    • default 30
    • Defines the rate in frames per second with which setState is called
  • leading <bool>
    • default false
    • Calls setState on the leading edge (right away). When false setState will not be called until the next frame is due
Returns [value: any, setValue: function]: array
  • value
    • The value set by setValue or the initialValue
  • setValue
    • A throttled setState callback

useThrottleCallback(fn: function, fps?: number, leading?: bool)

  • fn <any>
    • This is the callback you want to throttle
  • fps <number>
    • default 30
    • Defines the rate in frames per second with which setState is called
  • leading <bool>
    • default false
    • Calls setState on the leading edge (right away). When false setState will not be called until the next frame is due
Returns setValue: function
  • throttledFn
    • The throttled fn callback

Keywords

FAQs

Package last updated on 23 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc