@tevhooks/use-debounce
v1.0.0
Published
a react hook to act as a debounce wrapper
Downloads
8
Readme
use-debounce
a react hook that helps debounce expensive function calls in functional components.
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.