Skip to content

Commit

Permalink
chore(deps): update @algolia/client-search to v5 (major) (#7979)
Browse files Browse the repository at this point in the history
* chore(deps): update algoliasearch-client-javascript monorepo to v5

* Fix API usage

* Fix example

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Lachlan Collins <1667261+lachlancollins@users.noreply.github.com>
  • Loading branch information
renovate[bot] and lachlancollins authored Aug 29, 2024
1 parent f240106 commit 189e0c5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 160 deletions.
4 changes: 1 addition & 3 deletions examples/react/algolia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
"test:types": "tsc"
},
"dependencies": {
"@algolia/client-search": "4.24.0",
"@algolia/transporter": "4.24.0",
"@algolia/client-search": "5.2.1",
"@tanstack/react-query": "^5.52.2",
"@tanstack/react-query-devtools": "^5.52.2",
"algoliasearch": "4.24.0",
"react": "19.0.0-rc-4c2e457c7c-20240522",
"react-dom": "19.0.0-rc-4c2e457c7c-20240522"
},
Expand Down
17 changes: 8 additions & 9 deletions examples/react/algolia/src/algolia.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import algoliasearch from 'algoliasearch'
import { Hit } from '@algolia/client-search'
import { searchClient } from '@algolia/client-search'
import type { Hit } from '@algolia/client-search'

// From Algolia example
// https://github.com/algolia/react-instantsearch
Expand All @@ -19,17 +19,16 @@ export async function search<TData>({
pageParam,
hitsPerPage = 10,
}: SearchOptions): Promise<{
hits: Hit<TData>[]
hits: Array<Hit<TData>>
nextPage: number | undefined
}> {
const client = algoliasearch(ALGOLIA_APP_ID, ALGOLIA_SEARCH_API_KEY)
const index = client.initIndex(indexName)
const client = searchClient(ALGOLIA_APP_ID, ALGOLIA_SEARCH_API_KEY)

console.log('alogolia:search', { indexName, query, pageParam, hitsPerPage })
console.log('algolia:search', { indexName, query, pageParam, hitsPerPage })

const { hits, page, nbPages } = await index.search<TData>(query, {
page: pageParam,
hitsPerPage,
const { hits, page, nbPages } = await client.searchSingleIndex<TData>({
indexName,
searchParams: { query, page: pageParam, hitsPerPage },
})

const nextPage = page + 1 < nbPages ? page + 1 : undefined
Expand Down
4 changes: 2 additions & 2 deletions examples/react/algolia/src/useAlgolia.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useInfiniteQuery, skipToken } from '@tanstack/react-query'
import { skipToken, useInfiniteQuery } from '@tanstack/react-query'
import { search } from './algolia'

export type UseAlgoliaOptions = {
Expand All @@ -23,7 +23,7 @@ export default function useAlgolia<TData>({
search<TData>({ indexName, query, pageParam, hitsPerPage })
: skipToken,
initialPageParam: 0,
getNextPageParam: (lastPage) => lastPage?.nextPage,
getNextPageParam: (lastPage) => lastPage.nextPage,
staleTime,
gcTime,
})
Expand Down
182 changes: 36 additions & 146 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 189e0c5

Please sign in to comment.