Skip to content

Commit 2716648

Browse files
committed
feat: add enabled prop
1 parent 0eb314a commit 2716648

File tree

9 files changed

+37
-5
lines changed

9 files changed

+37
-5
lines changed

packages/recommend-react/src/FrequentlyBoughtTogether.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const UncontrolledFrequentlyBoughtTogether = createFrequentlyBoughtTogetherCompo
1717

1818
export type UseFrequentlyBoughtTogetherProps<TObject> = OptionalRecommendClient<
1919
GetFrequentlyBoughtTogetherProps<TObject>
20-
>;
20+
> & { enabled?: boolean };
2121

2222
export type FrequentlyBoughtTogetherProps<
2323
TObject

packages/recommend-react/src/RelatedProducts.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const UncontrolledRelatedProducts = createRelatedProductsComponent({
1515

1616
export type UseRelatedProductsProps<TObject> = OptionalRecommendClient<
1717
GetRelatedProductsProps<TObject>
18-
>;
18+
> & { enabled?: boolean };
1919

2020
export type RelatedProductsProps<TObject> = UseRelatedProductsProps<TObject> &
2121
Omit<

packages/recommend-react/src/TrendingFacets.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const UncontrolledTrendingFacets = createTrendingFacetsComponent({
1515

1616
export type UseTrendingFacetsProps<TObject> = OptionalRecommendClient<
1717
GetTrendingFacetsProps<TObject>
18-
>;
18+
> & { enabled?: boolean };
1919

2020
export type TrendingFacetsProps<TObject> = UseTrendingFacetsProps<TObject> &
2121
Omit<

packages/recommend-react/src/TrendingItems.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const UncontrolledTrendingItems = createTrendingItemsComponent({
1515

1616
export type UseTrendingItemsProps<TObject> = OptionalRecommendClient<
1717
GetTrendingItemsProps<TObject>
18-
>;
18+
> & { enabled?: boolean };
1919

2020
export type TrendingItemsProps<TObject> = UseTrendingItemsProps<TObject> &
2121
Omit<

packages/recommend-react/src/useFrequentlyBoughtTogether.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useStableValue } from './useStableValue';
1212
import { useStatus } from './useStatus';
1313

1414
export function useFrequentlyBoughtTogether<TObject>({
15+
enabled = true,
1516
indexName,
1617
maxRecommendations,
1718
objectIDs: userObjectIDs,
@@ -38,6 +39,10 @@ export function useFrequentlyBoughtTogether<TObject>({
3839
}, [userTransformItems]);
3940

4041
useEffect(() => {
42+
if (!enabled) {
43+
return;
44+
}
45+
4146
const param = {
4247
indexName,
4348
maxRecommendations,
@@ -90,6 +95,7 @@ export function useFrequentlyBoughtTogether<TObject>({
9095
});
9196
return () => {};
9297
}, [
98+
enabled,
9399
indexName,
94100
maxRecommendations,
95101
objectIDs,

packages/recommend-react/src/useRecommendations.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import { useAlgoliaAgent } from './useAlgoliaAgent';
99
import { useStableValue } from './useStableValue';
1010
import { useStatus } from './useStatus';
1111

12-
export type UseRecommendationsProps<TObject> = GetRecommendationsProps<TObject>;
12+
export type UseRecommendationsProps<
13+
TObject
14+
> = GetRecommendationsProps<TObject> & { enabled?: boolean };
1315

1416
export function useRecommendations<TObject>({
17+
enabled = true,
1518
fallbackParameters: userFallbackParameters,
1619
indexName,
1720
maxRecommendations,
@@ -38,6 +41,10 @@ export function useRecommendations<TObject>({
3841
}, [userTransformItems]);
3942

4043
useEffect(() => {
44+
if (!enabled) {
45+
return;
46+
}
47+
4148
setStatus('loading');
4249
getRecommendations({
4350
fallbackParameters,
@@ -54,6 +61,7 @@ export function useRecommendations<TObject>({
5461
setStatus('idle');
5562
});
5663
}, [
64+
enabled,
5765
fallbackParameters,
5866
indexName,
5967
maxRecommendations,

packages/recommend-react/src/useRelatedProducts.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useStableValue } from './useStableValue';
1212
import { useStatus } from './useStatus';
1313

1414
export function useRelatedProducts<TObject>({
15+
enabled = true,
1516
fallbackParameters: userFallbackParameters,
1617
indexName,
1718
maxRecommendations,
@@ -40,6 +41,10 @@ export function useRelatedProducts<TObject>({
4041
}, [userTransformItems]);
4142

4243
useEffect(() => {
44+
if (!enabled) {
45+
return;
46+
}
47+
4348
const param = {
4449
fallbackParameters,
4550
indexName,
@@ -95,6 +100,7 @@ export function useRelatedProducts<TObject>({
95100
return () => {};
96101
}, [
97102
client,
103+
enabled,
98104
fallbackParameters,
99105
hasProvider,
100106
indexName,

packages/recommend-react/src/useTrendingFacets.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useAlgoliaAgent } from './useAlgoliaAgent';
1212
import { useStatus } from './useStatus';
1313

1414
export function useTrendingFacets<TObject>({
15+
enabled = true,
1516
indexName,
1617
maxRecommendations,
1718
recommendClient,
@@ -35,6 +36,10 @@ export function useTrendingFacets<TObject>({
3536
}, [userTransformItems]);
3637

3738
useEffect(() => {
39+
if (!enabled) {
40+
return;
41+
}
42+
3843
const param = {
3944
model: 'trending-facets' as TrendingModel,
4045
indexName,
@@ -79,6 +84,7 @@ export function useTrendingFacets<TObject>({
7984
});
8085
return () => {};
8186
}, [
87+
enabled,
8288
indexName,
8389
maxRecommendations,
8490
client,

packages/recommend-react/src/useTrendingItems.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useStableValue } from './useStableValue';
1212
import { useStatus } from './useStatus';
1313

1414
export function useTrendingItems<TObject>({
15+
enabled = true,
1516
fallbackParameters: userFallbackParameters,
1617
indexName,
1718
maxRecommendations,
@@ -40,6 +41,10 @@ export function useTrendingItems<TObject>({
4041
}, [userTransformItems]);
4142

4243
useEffect(() => {
44+
if (!enabled) {
45+
return;
46+
}
47+
4348
const param: BatchQuery<TObject> = {
4449
model: 'trending-items',
4550
fallbackParameters,
@@ -86,6 +91,7 @@ export function useTrendingItems<TObject>({
8691
});
8792
return () => {};
8893
}, [
94+
enabled,
8995
fallbackParameters,
9096
indexName,
9197
maxRecommendations,

0 commit comments

Comments
 (0)