mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-26 04:00:13 +08:00
7a3bf8287f
* chore: bump rc-field-form * docs: Demo driven * refactor: Use event instead * chore: collection logic update * chore: clean up * chore: show warning * chore: warning no need required mark * feat: warning example * docs: mix error * chore: tmp list * chore: magic code * chore: fix motion * chore: fix style * chore: clean up useless code * chore: RM useless import * chore: RM useless file * test: Update snapshot * chore: Should reset * fix: Memo logic * fix: Form basic test case * fix: lint * chore: back of ref * test: Update snapshot * test: RM ueseless test case * chore: RM useless code
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;
|
|
}
|