Skip to content

Commit 509429c

Browse files
Search bar query (TheAlgorithms#254)
* Remove search results if the query is null. * Remove search results if the query is null. * Apply suggestions from code review * Whoops --------- Co-authored-by: David Leal <[email protected]>
1 parent 80c3238 commit 509429c

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

components/searchBar/index.tsx

+6-7
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ export default function SearchBar({
3838

3939
function handleInput(event: FormEvent) {
4040
setQuery((event.target as HTMLInputElement).value);
41-
4241
// When input value is null, set error & empty state to `true` and do nothing.
42+
43+
if (!smallScreen)
44+
debounce(() => {
45+
router.push(`/search?q=${(event.target as HTMLInputElement).value}`);
46+
});
4347
if (!(event.target as HTMLInputElement).value) {
4448
setIsEmpty(true);
4549
setIsError(true);
@@ -49,12 +53,7 @@ export default function SearchBar({
4953
// When input value is not null, reset error & empty state to `false`.
5054
// And also debounce the router push.
5155
setIsError(false);
52-
setIsEmpty(false);
53-
54-
if (!smallScreen)
55-
debounce(() => {
56-
router.push(`/search?q=${(event.target as HTMLInputElement).value}`);
57-
});
56+
setIsEmpty(false);
5857
}
5958

6059
function handleSubmit(event?: FormEvent) {

0 commit comments

Comments
 (0)