diff --git a/packages/nextjs/src/newsroom-context/hooks/useSearchClient.ts b/packages/nextjs/src/newsroom-context/hooks/useSearchClient.ts index 3982c7110..31f96128a 100644 --- a/packages/nextjs/src/newsroom-context/hooks/useSearchClient.ts +++ b/packages/nextjs/src/newsroom-context/hooks/useSearchClient.ts @@ -1,9 +1,8 @@ -import { instantMeiliSearch } from '@meilisearch/instant-meilisearch'; import type { SearchSettings } from '@prezly/theme-kit-core/server'; -import algoliasearch from 'algoliasearch/lite'; +import { useMemo } from 'react'; + +import { getSearchClient } from '../utils'; export function useSearchClient(settings: SearchSettings) { - return settings.searchBackend === 'algolia' - ? algoliasearch(settings.appId, settings.apiKey) - : instantMeiliSearch(settings.host, settings.apiKey).searchClient; + return useMemo(() => getSearchClient(settings), [settings]); }