From 407d57d6333c791144e7ee2b909695c7320874bf Mon Sep 17 00:00:00 2001 From: DukeManh Date: Mon, 8 Feb 2021 15:31:51 -0500 Subject: [PATCH] Triggering search through URL --- src/frontend/next/src/components/SearchPage.tsx | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/frontend/next/src/components/SearchPage.tsx b/src/frontend/next/src/components/SearchPage.tsx index d918ed2533..f6bec0afb8 100644 --- a/src/frontend/next/src/components/SearchPage.tsx +++ b/src/frontend/next/src/components/SearchPage.tsx @@ -23,12 +23,10 @@ const SearchPage = () => { // We synchronize the `text` and `filter` values to the URL's query string // Router query object for a query can be an array if url becomes text=123&text=456 // https://stackoverflow.com/questions/60110364/type-string-string-is-not-assignable-to-type-string - const [textParam = '', setTextParam] = useState( - Array.isArray(router.query.text) ? router.query.text[0] : router.query.text - ); - const [filterParam = 'post', setFilterParam] = useState( - router.query.filter === 'post' ? 'post' : 'author' - ); + const textParam = Array.isArray(router.query.text) + ? router.query.text[0] + : router.query.text || ''; + const filterParam = router.query.filter === 'post' ? 'post' : 'author'; // We manage the state of `text` and `filter` internally, and update URL on // form submit only. These are used in the , and the user can change them. @@ -38,8 +36,6 @@ const SearchPage = () => { // Form was submitted, so go ahead and sync to URL, (re)triggering search. function onSubmitHandler(event: FormEvent) { event.preventDefault(); - setTextParam(text); - setFilterParam(filter); router.push(`/search?text=${text}&filter=${filter}`); }