React 实现搜索防抖
import React from "react";
export default function debounce<T = HTMLInputElement>(
fn: (ev: React.ChangeEvent<T>) => void,
ms = 500
) {
let timeId: NodeJS.Timeout;
return (ev: React.ChangeEvent<T>) => {
clearTimeout(timeId);
timeId = setTimeout(() => {
fn(ev);
}, ms);
};
}