use-throttled-callback
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

useThrottledCallback

Prerequisites

NPM

npm install react react-dom

Yarn

yarn add react react-dom

Install

With npm

npm install use-throttled-callback

With Yarn

yarn add use-throttled-callback

Usage

import React, { ChangeEvent, useState } from 'react'
import { useThrottledCallback } from 'use-throttled-callback'
 
const FuncComp = () => {
  const [text, setText] = useState('')
 
  const { flush, result: handleThrottledChange } = useThrottledCallback(
    (e: ChangeEvent<HTMLInputElement>) => {
      setText(e.target.value)
    },
    10000,
    [],
  )
 
  return (
    <div>
      <button onClick={flush}>Click me to reset the callback throttling!</button>
 
      <input onChange={handleThrottledChange} />
 
      {text}
    </div>
  )
}

Readme

Keywords

none

Package Sidebar

Install

npm i use-throttled-callback

Weekly Downloads

2

Version

2.0.0

License

MIT

Unpacked Size

3.52 kB

Total Files

8

Last publish

Collaborators

  • valerio.belli