Skip to content

Latest commit

 

History

History
 
 

throttle-handler

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

⌛ throttle-handler

npm ci coverage deps

Part of a collection of Higher-Order Components for React, especially useful with Recompose.

Helps to throttle handlers like onChange.

Install

yarn add @hocs/throttle-handler

Usage

throttleHandler(
  handlerName: string,
  interval?: number,
  leadingCall?: boolean
): HigherOrderComponent
import React from 'react';
import { compose, withState, withHandlers } from 'recompose';
import throttleHandler from '@hocs/throttle-handler';

const Demo = ({ count, onButtonClick }) => (
  <div>
    <h1>{count}</h1>
    <button onClick={onButtonClick}>CLICK ME FAST</button>
  </div>
);

export default compose(
  withState('count', 'setCount', 0),
  withHandlers({
    onButtonClick: ({ count, setCount }) => () => setCount(count + 1)
  }),
  throttleHandler('onButtonClick', 1000)
)(Demo);

📺 Check out live demo.