From 0af1c625d45af5d64c75978304dfd391920820ac Mon Sep 17 00:00:00 2001 From: developomp Date: Wed, 1 Sep 2021 16:38:33 +0900 Subject: [PATCH] search on page load --- source/src/pages/Search.tsx | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/source/src/pages/Search.tsx b/source/src/pages/Search.tsx index 75a9576..ff1af3c 100644 --- a/source/src/pages/Search.tsx +++ b/source/src/pages/Search.tsx @@ -106,7 +106,7 @@ export default function Search() { } function _Search() { - const [index, setIndex] = useState({} as elasticlunr.Index) + const [index] = useState(elasticlunr.Index.load(searchIndex as never)) const inputRef = useRef(null) const _history = useHistory() @@ -135,10 +135,6 @@ function _Search() { const [searchInput, setSearchInput] = useState(query.query) function doSearch() { - // remove focus from search bar to prevent accidental multiple search - // if (document.activeElement instanceof HTMLElement) - // document.activeElement.blur() - _history.push({ pathname: "/search", search: queryString.stringify({ @@ -182,14 +178,11 @@ function _Search() { setPostCards(_postCards) } // eslint-disable-next-line no-empty - } catch (err) {} + } catch (err) { + console.error(err) + } } - // load search index only once - useEffect(() => { - setIndex(elasticlunr.Index.load(searchIndex as never)) - }, []) - useEffect(() => { doSearch() }, [dateRange])