useRemovePasswordTimeout.js 972 B

1234567891011121314151617181920212223
  1. import { useEffect, useRef } from 'react';
  2. export default function useRemovePasswordTimeout(inputRef, triggerOnMount) {
  3. const removePasswordTimeoutRef = useRef([]);
  4. const removePasswordTimeout = () => {
  5. removePasswordTimeoutRef.current.push(setTimeout(() => {
  6. var _a, _b, _c, _d;
  7. if (((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.input) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.input.getAttribute('type')) === 'password' && ((_c = inputRef.current) === null || _c === void 0 ? void 0 : _c.input.hasAttribute('value'))) {
  8. (_d = inputRef.current) === null || _d === void 0 ? void 0 : _d.input.removeAttribute('value');
  9. }
  10. }));
  11. };
  12. useEffect(() => {
  13. if (triggerOnMount) {
  14. removePasswordTimeout();
  15. }
  16. return () => removePasswordTimeoutRef.current.forEach(timer => {
  17. if (timer) {
  18. clearTimeout(timer);
  19. }
  20. });
  21. }, []);
  22. return removePasswordTimeout;
  23. }