summaryrefslogtreecommitdiff
path: root/src/core/components/elements/Navbar/Search.jsx
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-03-10 17:23:04 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-03-10 17:23:04 +0700
commit1218d8109380488ab7d15538fe3f828883dbc822 (patch)
tree3ab8cd620dc452f8ac738bf942cd8ba9ec43d291 /src/core/components/elements/Navbar/Search.jsx
parent89d10a897869f34cd5d67fe56cafad3aa55531b6 (diff)
change mobile and desktop view
Diffstat (limited to 'src/core/components/elements/Navbar/Search.jsx')
-rw-r--r--src/core/components/elements/Navbar/Search.jsx14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/core/components/elements/Navbar/Search.jsx b/src/core/components/elements/Navbar/Search.jsx
index e78f7f29..32a8d170 100644
--- a/src/core/components/elements/Navbar/Search.jsx
+++ b/src/core/components/elements/Navbar/Search.jsx
@@ -7,20 +7,14 @@ import { useRouter } from 'next/router'
const Search = () => {
const router = useRouter()
const queryRef = useRef()
- const [query, setQuery] = useState('')
+ const [query, setQuery] = useState(router.query.q || '')
const [suggestions, setSuggestions] = useState([])
- useEffect(() => {
- setQuery(router.query.q)
- }, [router.query])
-
const loadSuggestion = useCallback(() => {
if (query && document.activeElement == queryRef.current) {
- ;(async () => {
- const dataSuggestion = await searchSuggestApi({ query })
- setSuggestions(dataSuggestion.data.suggestions)
- })()
- return
+ searchSuggestApi({ query }).then((response) => {
+ setSuggestions(response.data.suggestions)
+ })
} else {
setSuggestions([])
}