mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 05:19:39 +02:00
fix(nameField): imperatively call setDebouncedValue when the value is changed by setFieldValue [EE-5002] (#8468)
Co-authored-by: testa113 <testa113>
This commit is contained in:
parent
cef9255161
commit
5c05ec489e
2 changed files with 14 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
|||
import _ from 'lodash';
|
||||
import { useState, useRef } from 'react';
|
||||
import { useState, useRef, useCallback } from 'react';
|
||||
|
||||
export function useDebounce(
|
||||
defaultValue: string,
|
||||
|
@ -9,10 +9,13 @@ export function useDebounce(
|
|||
|
||||
const onChangeDebounces = useRef(_.debounce(onChange, 300));
|
||||
|
||||
return [searchValue, handleChange] as const;
|
||||
const handleChange = useCallback(
|
||||
(value: string) => {
|
||||
setSearchValue(value);
|
||||
onChangeDebounces.current(value);
|
||||
},
|
||||
[onChangeDebounces, setSearchValue]
|
||||
);
|
||||
|
||||
function handleChange(value: string) {
|
||||
setSearchValue(value);
|
||||
onChangeDebounces.current(value);
|
||||
}
|
||||
return [searchValue, handleChange] as const;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue