mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 15:59:41 +02:00
fix(wizard): debounce name state [EE-4177] (#8042)
move debouncing to the component (from the validation). debounce returns undefined when it's not calling the debounced function, and undefined is considered a validation error.
This commit is contained in:
parent
253a3a2b40
commit
7006c17ce4
9 changed files with 74 additions and 58 deletions
15
app/react/hooks/useDebouncedValue.ts
Normal file
15
app/react/hooks/useDebouncedValue.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { useEffect, useState } from 'react';
|
||||
|
||||
export function useDebouncedValue<T>(value: T, delay = 500): T {
|
||||
const [debouncedValue, setDebouncedValue] = useState<T>(value);
|
||||
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => setDebouncedValue(value), delay);
|
||||
|
||||
return () => {
|
||||
clearTimeout(timer);
|
||||
};
|
||||
}, [value, delay]);
|
||||
|
||||
return debouncedValue;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue