Skip to content

Commit 4e0e71e

Browse files
authored
Merge pull request #159 from LoMonacoSalvatore/patch-1
Added optional key to useAlgoliaRecommend
2 parents 3ecdb90 + 8926b20 commit 4e0e71e

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

docs/content/1.getting-started/3.usage.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,15 @@ onMounted(async () => {
103103
})
104104
</script>
105105
```
106+
This composable returns the following:
106107

107108
* `result` will contain a value of a get method. It is reactive computed property that will be populated when a get method will fulfill. This result will have a form described [here](https://www.algolia.com/doc/api-reference/api-methods/get-recommendations/#response)
108109
* `get` method is used to get the recommendations based on the criteria described [here](https://www.algolia.com/doc/api-reference/api-methods/get-recommendations/#parameters) and an optional parameter of `requestOptions` that you can check out [here](https://www.algolia.com/doc/api-reference/api-methods/search/#method-param-requestoptions)
109110

111+
This composable also accepts an optional key parameter:
112+
113+
* `key` - if you need multiple useAlgoliaRecommend calls, add a unique key to get passed to the userState('recommend-result') underneath, so new calls won't overwrite old data.
114+
110115
For more details check out the official documentation of this method [here](https://www.algolia.com/doc/api-reference/api-methods/get-recommendations/)
111116

112117
## `useAlgoliaRef`

src/runtime/composables/useAlgoliaRecommend.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ export type UseAlgoliaRecommend<T> = {
1414
get: (params: RecommendParams) => Promise<MultipleQueriesResponse<T>>
1515
}
1616

17-
export function useAlgoliaRecommend<T> (): UseAlgoliaRecommend<T> {
17+
export function useAlgoliaRecommend<T> (key: string = ''): UseAlgoliaRecommend<T> {
1818
const { $algoliaRecommend } = useNuxtApp()
1919
const algoliaRecommend: RecommendClient = $algoliaRecommend
2020

2121
if (!$algoliaRecommend) {
2222
throw new Error('`[@nuxtjs/algolia]` Cannot call useAlgoliaRecommend composable due to missing `algolia.recommend` option.')
2323
}
2424

25-
const result = useState('recommend-result', () => null)
25+
const result = useState(`recommend-result${key ? '-' + key : ''}`, () => null)
2626

2727
const get = async ({ queries, requestOptions }: RecommendParams) => {
2828
result.value = await algoliaRecommend.getRecommendations<T>(queries, requestOptions)

0 commit comments

Comments
 (0)