useDebounce

React hook for debounced values and functions.

Source code is hosted on GitHubarrow-up-right

yarn add @corets/use-debounce

useDebounce()

This hook is built on top of debounce()arrow-up-right from lodash and accepts the same arguments.

Example of a debounced value:

import React, { useState, useEffect } from "react"
import { useDebounce } from "@corets/use-debounce"

const Example = () => {
  const [input, setInput] = useState("")
  const debouncedInput = useDebounce(input, 300)
  
  const handleSearch = () => {
    // fetch some data based on input...
  }
  
  const handleChange = (e) => setInput(e.target.value)
  
  // react to changes of the debounced input
  useEffect(handleSearch, [debouncedInput])
  
  return (
    <input type="text" onChange={handleChange} />
  )
}

Example of a debounced function:

circle-info

This hook accepts a third argument, identical to the one expected by the debounce()arrow-up-right function from lodash.

Last updated

Was this helpful?