Skip to content

Latest commit

 

History

History
42 lines (33 loc) · 689 Bytes

File metadata and controls

42 lines (33 loc) · 689 Bytes

Installation

$ npm install react-debouncing

Or :

$ yarn add react-debouncing

Example

import React, { Component } from 'react';
import debounce from 'react-debouncing';

class Debounce extends Component {
  state = {
    count: 0,
  };

  increment = debounce(() => {
    this.setState({
      count: this.state.count + 1,
    });
  }, 500);

  decrement = debounce(() => {
    this.setState({
      count: this.state.count - 1,
    });
  }, 500);

  render() {
    return (
      <div>
        <div>{this.state.count}</div>
        <button onClick={this.increment}> + </button>
        <button onClick={this.decrement}> - </button>
      </div>
    );
  }
}