mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-21 04:48:02 +08:00
ac5a06027e
This reverts commit ea8ed28209
.
20 lines
394 B
TypeScript
20 lines
394 B
TypeScript
import * as React from 'react';
|
|
|
|
export default function useDebounce<T>(value: T[]): T[] {
|
|
const [cacheValue, setCacheValue] = React.useState(value);
|
|
React.useEffect(() => {
|
|
const timeout = setTimeout(
|
|
() => {
|
|
setCacheValue(value);
|
|
},
|
|
value.length ? 0 : 10,
|
|
);
|
|
|
|
return () => {
|
|
clearTimeout(timeout);
|
|
};
|
|
}, [value]);
|
|
|
|
return cacheValue;
|
|
}
|