Skip to content

Commit

Permalink
Cancel debounced URL updating on component dismount
Browse files Browse the repository at this point in the history
  • Loading branch information
kasbah committed Sep 23, 2024
1 parent 02b811b commit 0b9c94f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion frontend/src/components/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,19 @@ const SearchInput = () => {
debounce(value => {
const path = value ? `/search?q=${encodeURIComponent(value)}` : '/'
replace(path, undefined, { shallow: true })
}, 1000),
}, 500),
)

// cancel on component dismount
useEffect(() => {
return () => {
// I don't understand what react / eslint wants us to do in this case:
// the ref doesn't actually change.
// eslint-disable-next-line react-hooks/exhaustive-deps
debouncedUpdateUrl.current.cancel()
}
}, [])

const handleChange = (value: string) => {
debouncedSubmit.current.cancel()
debouncedUpdateUrl.current.cancel()
Expand Down

0 comments on commit 0b9c94f

Please sign in to comment.