Rev 6992 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React, { useRef, useState } from 'react'
import { useForm } from 'react-hook-form'
import SearchIcon from '@mui/icons-material/Search'
import useWindowSize from '../../../../hooks/useWindowSize'
const NavSearch = () => {
const [showMobileSearch, setShowMobileSearch] = useState(false)
const searchInput = useRef(null)
const [innerWidth] = useWindowSize()
const { handleSubmit, register } = useForm()
const toggleSearch = () => {
setShowMobileSearch(!showMobileSearch)
}
const onSubmit = handleSubmit((data) => {
window.location.replace(`/search/entity/user?keyword=${data.keyword}`)
})
return (
<form
className="header__search show"
onClick={innerWidth < 992 && toggleSearch}
onSubmit={onSubmit}
ref={searchInput}
>
<SearchIcon />
<input type="text" placeholder="Search" name="keyword" ref={register} />
</form>
)
}
export default NavSearch