summaryrefslogtreecommitdiff
path: root/src/core/components/elements/Navbar/Search.jsx
diff options
context:
space:
mode:
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([])
}