@tobq/loadable
Version:
A library for simplifying asynchronous operations in React
28 lines (27 loc) • 795 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.currentTimestamp = currentTimestamp;
exports.useAbort = useAbort;
const react_1 = require("react");
function currentTimestamp() {
return new Date().valueOf();
}
function useAbort() {
const abortController = (0, react_1.useRef)(undefined);
const abort = () => {
const current = abortController.current;
const next = new AbortController();
abortController.current = next;
if (current) {
current.abort();
// console.debug("Triggered abort signal and replaced abort controller")
}
return next.signal;
};
(0, react_1.useEffect)(() => {
return () => {
abort();
};
}, []);
return abort;
}