linkmore-design
Version:
π πlmη»δ»ΆεΊγπ
26 lines β’ 1.29 kB
JavaScript
import { useEffect, useRef } from 'react';
export default function useRemovePasswordTimeout(inputRef, triggerOnMount) {
var removePasswordTimeoutRef = useRef([]);
var removePasswordTimeout = function removePasswordTimeout() {
removePasswordTimeoutRef.current.push(setTimeout(function () {
var _inputRef$current, _inputRef$current2, _inputRef$current3;
if ((_inputRef$current = inputRef.current) !== null && _inputRef$current !== void 0 && _inputRef$current.input && ((_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.input.getAttribute('type')) === 'password' && (_inputRef$current3 = inputRef.current) !== null && _inputRef$current3 !== void 0 && _inputRef$current3.input.hasAttribute('value')) {
var _inputRef$current4;
(_inputRef$current4 = inputRef.current) === null || _inputRef$current4 === void 0 ? void 0 : _inputRef$current4.input.removeAttribute('value');
}
}));
};
useEffect(function () {
if (triggerOnMount) {
removePasswordTimeout();
}
return function () {
return removePasswordTimeoutRef.current.forEach(function (timer) {
if (timer) {
clearTimeout(timer);
}
});
};
}, []);
return removePasswordTimeout;
}