first commit
This commit is contained in:
30
frontend/node_modules/rc-motion/es/hooks/useNextFrame.js
generated
vendored
Normal file
30
frontend/node_modules/rc-motion/es/hooks/useNextFrame.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import raf from "rc-util/es/raf";
|
||||
import * as React from 'react';
|
||||
export default (function () {
|
||||
var nextFrameRef = React.useRef(null);
|
||||
function cancelNextFrame() {
|
||||
raf.cancel(nextFrameRef.current);
|
||||
}
|
||||
function nextFrame(callback) {
|
||||
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
||||
cancelNextFrame();
|
||||
var nextFrameId = raf(function () {
|
||||
if (delay <= 1) {
|
||||
callback({
|
||||
isCanceled: function isCanceled() {
|
||||
return nextFrameId !== nextFrameRef.current;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
nextFrame(callback, delay - 1);
|
||||
}
|
||||
});
|
||||
nextFrameRef.current = nextFrameId;
|
||||
}
|
||||
React.useEffect(function () {
|
||||
return function () {
|
||||
cancelNextFrame();
|
||||
};
|
||||
}, []);
|
||||
return [nextFrame, cancelNextFrame];
|
||||
});
|
||||
Reference in New Issue
Block a user