I have a valid code, which runs when I change some text
import React, { useState } from "react";
const onChange = async ({ target: { value, name } }) => {
setErrors({ ...errors, [name]: false });
setUserData({ ...userData, [name]: value });
if (name === "address") {
const res = await searchAddress(value);
if (res.success) {
setAddressList(res?.results?.matches || []);
}
}
};
How can I execute searchAddress only if text change happened and previous call was later than 5 seconds?