diff --git a/components/searchBar/index.tsx b/components/searchBar/index.tsx index 4ac97a41..beeedb19 100644 --- a/components/searchBar/index.tsx +++ b/components/searchBar/index.tsx @@ -38,8 +38,12 @@ export default function SearchBar({ function handleInput(event: FormEvent) { setQuery((event.target as HTMLInputElement).value); - // When input value is null, set error & empty state to `true` and do nothing. + + if (!smallScreen) + debounce(() => { + router.push(`/search?q=${(event.target as HTMLInputElement).value}`); + }); if (!(event.target as HTMLInputElement).value) { setIsEmpty(true); setIsError(true); @@ -49,12 +53,7 @@ export default function SearchBar({ // When input value is not null, reset error & empty state to `false`. // And also debounce the router push. setIsError(false); - setIsEmpty(false); - - if (!smallScreen) - debounce(() => { - router.push(`/search?q=${(event.target as HTMLInputElement).value}`); - }); + setIsEmpty(false); } function handleSubmit(event?: FormEvent) {