mirror of
https://github.com/portainer/portainer.git
synced 2025-07-22 23:09: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
|
@ -1,9 +1,8 @@
|
|||
import { Search } from 'react-feather';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import _ from 'lodash';
|
||||
|
||||
import { useLocalStorage } from '@/react/hooks/useLocalStorage';
|
||||
import { AutomationTestingProps } from '@/types';
|
||||
import { useDebounce } from '@/react/hooks/useDebounce';
|
||||
|
||||
interface Props extends AutomationTestingProps {
|
||||
value: string;
|
||||
|
@ -34,26 +33,6 @@ export function SearchBar({
|
|||
);
|
||||
}
|
||||
|
||||
function useDebounce(defaultValue: string, onChange: (value: string) => void) {
|
||||
const [searchValue, setSearchValue] = useState(defaultValue);
|
||||
|
||||
useEffect(() => {
|
||||
setSearchValue(defaultValue);
|
||||
}, [defaultValue]);
|
||||
|
||||
const onChangeDebounces = useMemo(
|
||||
() => _.debounce(onChange, 300),
|
||||
[onChange]
|
||||
);
|
||||
|
||||
return [searchValue, handleChange] as const;
|
||||
|
||||
function handleChange(value: string) {
|
||||
setSearchValue(value);
|
||||
onChangeDebounces(value);
|
||||
}
|
||||
}
|
||||
|
||||
export function useSearchBarState(
|
||||
key: string
|
||||
): [string, (value: string) => void] {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue