1.0.0 • Published 4 years ago

@tevhooks/use-debounce v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

use-debounce

a react hook that helps debounce expensive function calls in functional components.

NPM JavaScript Style Guide

Install

npm install --save @tevhooks/use-debounce

Usage

import React, { Component } from 'react'

import useDebounce from '@tevhooks/use-debounce'

const Example = () => {
  const debouncedAPICall = useDebounce({
    fn: makeAPICall,
    wait: 1000
  })

  function makeAPICall(evt) {
    evt.persist()
    return fetch(`/endpoint?search=${evt.target.value}`)
  }

  return (
    <div>
      <input onChange={debouncedAPICall} />
    </div>
  )
}

Check out the example folder for more information

License

MIT © Tevinthuku


This hook is created using create-react-hook.

1.0.0

4 years ago