Skip to content

Commit

Permalink
Use getSearchClient utility in useSearchClient + add memoization
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriyyakym committed Jul 23, 2024
1 parent d194a7e commit 2fc215c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/nextjs/src/newsroom-context/hooks/useSearchClient.ts
Original file line number Diff line number Diff line change
@@ -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]);
}

0 comments on commit 2fc215c

Please sign in to comment.