This commit is contained in:
2026-05-25 17:08:18 +08:00
parent df501f6151
commit f1259b71b5
9178 changed files with 1626125 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
import * as React from 'react';
/**
* Locker return cached mark.
* If set to `true`, will return `true` in a short time even if set `false`.
* If set to `false` and then set to `true`, will change to `true`.
* And after time duration, it will back to `null` automatically.
*/
export default function useLock(duration = 250) {
const lockRef = React.useRef(null);
const timeoutRef = React.useRef(null);
// Clean up
React.useEffect(() => () => {
window.clearTimeout(timeoutRef.current);
}, []);
function doLock(locked) {
if (locked || lockRef.current === null) {
lockRef.current = locked;
}
window.clearTimeout(timeoutRef.current);
timeoutRef.current = window.setTimeout(() => {
lockRef.current = null;
}, duration);
}
return [() => lockRef.current, doLock];
}