From d986f438d95af2abbda99242c729664789c93212 Mon Sep 17 00:00:00 2001 From: Carlos Valente Date: Sun, 5 Oct 2025 09:42:33 +0200 Subject: [PATCH] refactor: improve delay component --- .../common/components/input/delay-input/DelayInput.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/client/src/common/components/input/delay-input/DelayInput.tsx b/apps/client/src/common/components/input/delay-input/DelayInput.tsx index 157fb90e4..76870796a 100644 --- a/apps/client/src/common/components/input/delay-input/DelayInput.tsx +++ b/apps/client/src/common/components/input/delay-input/DelayInput.tsx @@ -20,7 +20,7 @@ export default function DelayInput(props: DelayInputProps) { const [value, setValue] = useState(''); const inputRef = useRef(null); // avoid wrong submit on cancel - let ignoreChange = false; + const ignoreChangeRef = useRef(false); // set internal value on duration change useEffect(() => { @@ -35,8 +35,8 @@ export default function DelayInput(props: DelayInputProps) { * @param {string} newValue string to be parsed */ const validateAndSubmit = (newValue: string) => { - if (ignoreChange) { - ignoreChange = false; + if (ignoreChangeRef.current) { + ignoreChangeRef.current = false; return; } @@ -78,7 +78,7 @@ export default function DelayInput(props: DelayInputProps) { } else if (event.key === 'Tab') { validateAndSubmit((event.target as HTMLInputElement).value); } else if (event.key === 'Escape') { - ignoreChange = true; + ignoreChangeRef.current = true; setValue(millisToString(duration)); inputRef.current?.blur(); }