Introduction
Example
import AwesomeDebouncePromise from "awesome-debounce-promise";
const debounceAction = (actionFunc, delay) =>
AwesomeDebouncePromise(actionFunc, delay);
function useDebounce(func, delay) {
const debouncedFunction = useMemo(() => debounceAction(func, delay), [
delay,
func,
]);
return debouncedFunction;
}
import React from "react";
const callAPI = async (value) => {
// expensice API call
};
export default function Client() {
const debouncedAPICall = useDebounce(callAPI, 500);
const handleInputChange = async (e) => {
debouncedAPICall(e.target.value);
};
return (
<form>
<input type="text" onChange={handleInputChange} />
</form>
);
}