Skip to content

Commit

Permalink
Removes unnecessary search state (vercel#1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
manovotny authored Sep 18, 2023
1 parent b0f6e94 commit d9f875b
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions components/layout/navbar/search.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
'use client';

import { useRouter, useSearchParams } from 'next/navigation';
import { useEffect, useState } from 'react';

import { MagnifyingGlassIcon } from '@heroicons/react/24/outline';
import { createUrl } from 'lib/utils';
import { useRouter, useSearchParams } from 'next/navigation';

export default function Search() {
const router = useRouter();
const searchParams = useSearchParams();
const [searchValue, setSearchValue] = useState('');

useEffect(() => {
setSearchValue(searchParams?.get('q') || '');
}, [searchParams, setSearchValue]);

function onSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();
Expand All @@ -38,8 +31,7 @@ export default function Search() {
name="search"
placeholder="Search for products..."
autoComplete="off"
value={searchValue}
onChange={(e) => setSearchValue(e.target.value)}
defaultValue={searchParams?.get('q') || ''}
className="w-full rounded-lg border bg-white px-4 py-2 text-sm text-black placeholder:text-neutral-500 dark:border-neutral-800 dark:bg-transparent dark:text-white dark:placeholder:text-neutral-400"
/>
<div className="absolute right-0 top-0 mr-3 flex h-full items-center">
Expand Down

0 comments on commit d9f875b

Please sign in to comment.