ant-design/components/form/hooks/useDebounce.ts
二货机器人 7a3bf8287f
feat: Form rule support warningOnly that not block form submit (#30829)
* 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
2021-06-04 14:44:41 +08:00

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;
}