Files
video-gen/video-gen-admin/node_modules/@rc-component/motion/es/hooks/useNextFrame.js
T
2026-05-25 17:08:18 +08:00

25 lines
662 B
JavaScript

import raf from "@rc-component/util/es/raf";
import * as React from 'react';
export default (() => {
const nextFrameRef = React.useRef(null);
function cancelNextFrame() {
raf.cancel(nextFrameRef.current);
}
function nextFrame(callback, delay = 2) {
cancelNextFrame();
const nextFrameId = raf(() => {
if (delay <= 1) {
callback({
isCanceled: () => nextFrameId !== nextFrameRef.current
});
} else {
nextFrame(callback, delay - 1);
}
});
nextFrameRef.current = nextFrameId;
}
React.useEffect(() => () => {
cancelNextFrame();
}, []);
return [nextFrame, cancelNextFrame];
});