From 3ae83336bc4d6df651ace1e8415851ab89eac663 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 23 Mar 2022 21:53:53 -0400 Subject: [PATCH] Memoize the search bar Closes #149 --- components/SearchBar.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/SearchBar.tsx b/components/SearchBar.tsx index 4f601174..2266e9cf 100644 --- a/components/SearchBar.tsx +++ b/components/SearchBar.tsx @@ -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 = { collections: [], @@ -29,7 +30,7 @@ const initialAutocompleteState: AutocompleteState = { }; // Returns the search bar displayed in the header and the home page -export function SearchBar( +function SearchBarUnmemoized( props: Partial> & { overlay: boolean } ) { const [autocompleteState, setAutocompleteState] = useState< @@ -53,3 +54,5 @@ export function SearchBar( ); } + +export const SearchBar = React.memo(SearchBarUnmemoized);