Skip to content

Commit

Permalink
fix(search): Don't query algolia if search is not opened (#2465)
Browse files Browse the repository at this point in the history
Algolia is called once when the docs mount, we should make a query only if the search modal is opened
  • Loading branch information
AlexandreGaubert authored Oct 10, 2023
1 parent 320a926 commit a6532df
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/components/SearchEngine/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { BsSearch } from 'react-icons/bs';
import Results from './Results';
import { Page } from './types';

function useAlgoliaSearch(query: string) {
function useAlgoliaSearch(query: string, open: boolean) {
const [results, setResults] = useState<SearchResponse<Page>>();

useEffect(() => {
Expand All @@ -27,8 +27,8 @@ function useAlgoliaSearch(query: string) {
setResults(response);
};

search();
}, [query]);
open && search();
}, [query, open]);

return results;
}
Expand All @@ -37,7 +37,7 @@ export default function SearchBar() {
const [open, setOpen] = useState(false);
const [search, setSearch] = useState('');

const searchResults = useAlgoliaSearch(search);
const searchResults = useAlgoliaSearch(search, open);

const handleSearchChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setSearch(e.target.value);
Expand Down

0 comments on commit a6532df

Please sign in to comment.