first commit

This commit is contained in:
Stefan Hacker
2026-04-03 09:38:48 +02:00
commit 37ad745546
47450 changed files with 3120798 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSetInterval = void 0;
var React = require("react");
var useConst_1 = require("./useConst");
/**
* Returns a wrapper function for `setInterval` which automatically handles disposal.
*/
var useSetInterval = function () {
var intervalIds = (0, useConst_1.useConst)({});
React.useEffect(function () { return function () {
for (var _i = 0, _a = Object.keys(intervalIds); _i < _a.length; _i++) {
var id = _a[_i];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
clearInterval(id);
}
}; },
// useConst ensures this will never change, but react-hooks/exhaustive-deps doesn't know that
[intervalIds]);
return (0, useConst_1.useConst)({
setInterval: function (func, duration) {
var id = setInterval(func, duration);
intervalIds[id] = 1;
return id;
},
clearInterval: function (id) {
delete intervalIds[id];
clearInterval(id);
},
});
};
exports.useSetInterval = useSetInterval;
//# sourceMappingURL=useSetInterval.js.map