useDebounce
React hook for debounced values and functions.
yarn add @corets/use-debouncenpm install --save @corets/use-debounceuseDebounce()
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} />
)
}Last updated
Was this helpful?