diff --git a/packages/docsearch-react/src/Results.tsx b/packages/docsearch-react/src/Results.tsx index bff15a16..e4eff0c8 100644 --- a/packages/docsearch-react/src/Results.tsx +++ b/packages/docsearch-react/src/Results.tsx @@ -13,7 +13,7 @@ export type ResultsTranslations = Partial<{ }>; interface ResultsProps extends AutocompleteApi { - title: string; + title?: string | null; translations?: ResultsTranslations; collection: AutocompleteState['collections'][0]; renderIcon: (props: { item: TItem; index: number }) => React.ReactNode; @@ -25,7 +25,12 @@ interface ResultsProps export function Results(props: ResultsProps): JSX.Element | null { // The collection title, decoded to handle encoded HTML entities + // If there is not a title, return null to not render anything const decodedTitle = React.useMemo(() => { + if (!props.title) { + return null; + } + return props.title .replace(/&/g, '&') .replace(/</g, '<')