From a620f777b33e7527ede1cdd6d4fdf687fed81b3c Mon Sep 17 00:00:00 2001 From: Camila Belo Date: Tue, 21 Jun 2022 13:46:18 +0200 Subject: [PATCH] refactor(search): apply review suggestion Use search context checker in search modal and create local context only if needed. Signed-off-by: Camila Belo --- .../search/src/components/SearchModal/SearchModal.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/search/src/components/SearchModal/SearchModal.tsx b/plugins/search/src/components/SearchModal/SearchModal.tsx index aaee7667dd..dbb8100ec1 100644 --- a/plugins/search/src/components/SearchModal/SearchModal.tsx +++ b/plugins/search/src/components/SearchModal/SearchModal.tsx @@ -35,6 +35,7 @@ import { SearchResult, SearchResultPager, useSearch, + useSearchContextCheck, } from '@backstage/plugin-search-react'; import { useRouteRef } from '@backstage/core-plugin-api'; import { Link, useContent } from '@backstage/core-components'; @@ -172,13 +173,11 @@ export const Modal = ({ toggleModal }: SearchModalProps) => { const Context = ({ children }: PropsWithChildren<{}>) => { // Checks if there is a parent context already defined and, if not, creates a new local context. - try { - // Throws an exception if there is no parent context already defined - useSearch(); + const hasParentContext = useSearchContextCheck(); + if (hasParentContext) { return <>{children}; - } catch { - return {children}; } + return {children}; }; /**