|
1 | 1 | import { useSearchBox } from 'react-instantsearch'; |
2 | | -import React, { Dispatch, SetStateAction, useEffect, useState } from "react"; |
| 2 | +import React, { useEffect, useState } from "react"; |
3 | 3 | import { CancelIcon } from "../icons/cancel"; |
4 | 4 | import { useRouter } from "next/router"; |
5 | 5 |
|
6 | 6 | interface MobileSearchBoxProps { |
7 | | - refine: Dispatch<SetStateAction<string>>; |
| 7 | + refine: (value: string) => void; |
8 | 8 | onCloseCallback: () => void; |
9 | 9 | } |
10 | 10 |
|
11 | 11 | function SearchBox({ |
12 | 12 | refine, |
13 | 13 | onCloseCallback, |
14 | 14 | }: MobileSearchBoxProps) { |
15 | | - let [searchBarState, setSearchBarState] = useState(""); |
| 15 | + const [searchBarState, setSearchBarState] = useState(""); |
16 | 16 | useEffect(() => { |
17 | | - let searchBar = document.querySelector( |
| 17 | + const searchBar = document.querySelector( |
18 | 18 | "#algolia_search" |
19 | 19 | ) as HTMLInputElement; |
20 | 20 | if (searchBar != null) { |
@@ -53,14 +53,18 @@ function SearchBox({ |
53 | 53 | ); |
54 | 54 | } |
55 | 55 |
|
56 | | -function connectSearchBox(Component: any) { |
57 | | - const SearchBox = (props: any) => { |
58 | | - const data = useSearchBox(props); |
| 56 | +interface ConnectedMobileSearchBoxProps { |
| 57 | + onCloseCallback: () => void; |
| 58 | +} |
| 59 | + |
| 60 | +function connectSearchBox(Component: React.ComponentType<MobileSearchBoxProps>) { |
| 61 | + const ConnectedSearchBox = (props: ConnectedMobileSearchBoxProps) => { |
| 62 | + const data = useSearchBox(); |
59 | 63 |
|
60 | | - return <Component {...props} {...data} />; |
| 64 | + return <Component refine={data.refine} onCloseCallback={props.onCloseCallback} />; |
61 | 65 | }; |
62 | 66 |
|
63 | | - return SearchBox; |
| 67 | + return ConnectedSearchBox; |
64 | 68 | } |
65 | 69 |
|
66 | 70 | export default connectSearchBox(SearchBox); |
0 commit comments