MCPcopy Create free account
hub / github.com/microsoft/SandDance / useSetTimeout

Function useSetTimeout

docs/app/js/sanddance-app.js:34839–34866  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34837var _react = require("react");
34838var _useConst = require("./useConst");
34839var useSetTimeout = function() {
34840 var timeoutIds = (0, _useConst.useConst)({});
34841 // Cleanup function.
34842 _react.useEffect(function() {
34843 return function() {
34844 for(var _i = 0, _a = Object.keys(timeoutIds); _i < _a.length; _i++){
34845 var id = _a[_i];
34846 // eslint-disable-next-line @typescript-eslint/no-explicit-any
34847 clearTimeout(id);
34848 }
34849 };
34850 }, // useConst ensures this will never change, but react-hooks/exhaustive-deps doesn't know that
34851 [
34852 timeoutIds
34853 ]);
34854 // Return wrapper which will auto cleanup.
34855 return (0, _useConst.useConst)({
34856 setTimeout: function(func, duration) {
34857 var id = setTimeout(func, duration);
34858 timeoutIds[id] = 1;
34859 return id;
34860 },
34861 clearTimeout: function(id) {
34862 delete timeoutIds[id];
34863 clearTimeout(id);
34864 }
34865 });
34866};
34867
34868},{"react":"8ePka","./useConst":"jDC9C","@parcel/transformer-js/src/esmodule-helpers.js":"jA2du"}],"jHCdq":[function(require,module,exports) {
34869var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected