Skip to content

Commit

Permalink
Memoize the search bar
Browse files Browse the repository at this point in the history
Closes #149
  • Loading branch information
datho7561 committed Mar 24, 2022
1 parent e04b431 commit 3ae8333
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { SearchPanel, SearchPanelProps } from "./SearchPanel";
import { useAutocomplete } from "@lib/hooks/autocomplete";
import { AutocompleteItem } from "@lib/hooks/autocomplete";
import { Box } from "@chakra-ui/react";
import React from "react";

const initialAutocompleteState: AutocompleteState<AutocompleteItem> = {
collections: [],
Expand All @@ -29,7 +30,7 @@ const initialAutocompleteState: AutocompleteState<AutocompleteItem> = {
};

// Returns the search bar displayed in the header and the home page
export function SearchBar(
function SearchBarUnmemoized(
props: Partial<AutocompleteOptions<AutocompleteItem>> & { overlay: boolean }
) {
const [autocompleteState, setAutocompleteState] = useState<
Expand All @@ -53,3 +54,5 @@ export function SearchBar(
</Box>
);
}

export const SearchBar = React.memo(SearchBarUnmemoized);

0 comments on commit 3ae8333

Please sign in to comment.