Skip to content

Commit

Permalink
fix: fix the debounce of the asset top bar text field (#2219)
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmahidalgo committed Apr 16, 2024
1 parent 718c195 commit e86503e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions webapp/src/components/AssetTopbar/AssetTopbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,19 @@ export const AssetTopbar = ({
[category, onBrowse, search, section, shouldRenderSearchDropdown]
)
const [searchValue, setSearchValue] = useState(search)

const timeoutRef = useRef<NodeJS.Timeout | null>(null)
const handleDebouncedChange = useCallback(
(text: string) => {
if (timeoutRef.current) {
clearTimeout(timeoutRef.current)
}

setSearchValue(text)
const timeoutId = setTimeout(() => {

timeoutRef.current = setTimeout(() => {
handleInputChange(text)
}, 500)
return () => clearTimeout(timeoutId)
},
[handleInputChange]
)
Expand Down

0 comments on commit e86503e

Please sign in to comment.