This commit is contained in:
Luis Alvarez
2020-10-13 07:07:35 -05:00
parent e7e89e4c4c
commit ee6b65725f
9 changed files with 74 additions and 47 deletions

View File

@@ -24,14 +24,21 @@ const Searchbar: FC<Props> = ({ className }) => {
<input
className={s.input}
placeholder="Search for products..."
defaultValue={router.query.q}
onKeyUp={(e) => {
e.preventDefault()
if (e.key === 'Enter') {
router.push({
pathname: `/search`,
query: { q: e.currentTarget.value },
})
const q = e.currentTarget.value
router.push(
{
pathname: `/search`,
query: q ? { q } : {},
},
undefined,
{ shallow: true }
)
}
}}
/>