Skip to content

Commit c4a2f2c

Browse files
committed
sync query too
1 parent 6a5196f commit c4a2f2c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/components/search/InstantSearch.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ function SearchBox(props: UseSearchBoxProps) {
3434
}
3535
}, []);
3636

37+
useEffect(() => {
38+
const params = new URLSearchParams(window.location.search);
39+
40+
if (query) {
41+
params.set("q", query);
42+
} else {
43+
params.delete("q");
44+
}
45+
46+
history.pushState(
47+
null,
48+
"",
49+
`${window.location.pathname}?${params.toString()}`,
50+
);
51+
}, [query]);
52+
3753
return (
3854
<div className="border-cl1-gray-8 dark:border-cl1-gray-2 flex items-center rounded-sm border p-2">
3955
<input

0 commit comments

Comments
 (0)