Skip to content

Commit df22ca9

Browse files
committed
feat: add enabled prop
1 parent 6311b7f commit df22ca9

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
@@ -13,7 +13,7 @@ const UncontrolledTrendingFacets = createTrendingFacetsComponent({
1313
Fragment,
1414
});
1515

16-
export type UseTrendingFacetsProps = OptionalRecommendClient<GetTrendingFacetsProps>;
16+
export type UseTrendingFacetsProps = OptionalRecommendClient<GetTrendingFacetsProps> & { enabled?: boolean };
1717

1818
export type TrendingFacetsProps = UseTrendingFacetsProps &
1919
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,
@@ -40,6 +41,10 @@ export function useFrequentlyBoughtTogether<TObject>({
4041
}, [userTransformItems]);
4142

4243
useEffect(() => {
44+
if (!enabled) {
45+
return;
46+
}
47+
4348
const param = {
4449
indexName,
4550
maxRecommendations,
@@ -92,6 +97,7 @@ export function useFrequentlyBoughtTogether<TObject>({
9297
});
9398
return () => {};
9499
}, [
100+
enabled,
95101
indexName,
96102
maxRecommendations,
97103
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,
@@ -42,6 +43,10 @@ export function useRelatedProducts<TObject>({
4243
}, [userTransformItems]);
4344

4445
useEffect(() => {
46+
if (!enabled) {
47+
return;
48+
}
49+
4550
const param = {
4651
fallbackParameters,
4752
indexName,
@@ -97,6 +102,7 @@ export function useRelatedProducts<TObject>({
97102
return () => {};
98103
}, [
99104
client,
105+
enabled,
100106
fallbackParameters,
101107
hasProvider,
102108
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({
15+
enabled = true,
1516
indexName,
1617
maxRecommendations,
1718
recommendClient,
@@ -37,6 +38,10 @@ export function useTrendingFacets({
3738
}, [userTransformItems]);
3839

3940
useEffect(() => {
41+
if (!enabled) {
42+
return;
43+
}
44+
4045
const param = {
4146
model: 'trending-facets' as TrendingModel,
4247
indexName,
@@ -84,6 +89,7 @@ export function useTrendingFacets({
8489
});
8590
return () => {};
8691
}, [
92+
enabled,
8793
indexName,
8894
maxRecommendations,
8995
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,
@@ -42,6 +43,10 @@ export function useTrendingItems<TObject>({
4243
}, [userTransformItems]);
4344

4445
useEffect(() => {
46+
if (!enabled) {
47+
return;
48+
}
49+
4550
const param: BatchQuery<TObject> = {
4651
model: 'trending-items',
4752
fallbackParameters,
@@ -88,6 +93,7 @@ export function useTrendingItems<TObject>({
8893
});
8994
return () => {};
9095
}, [
96+
enabled,
9197
fallbackParameters,
9298
indexName,
9399
maxRecommendations,

0 commit comments

Comments
 (0)