File tree Expand file tree Collapse file tree 9 files changed +37
-5
lines changed
packages/recommend-react/src Expand file tree Collapse file tree 9 files changed +37
-5
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ const UncontrolledFrequentlyBoughtTogether = createFrequentlyBoughtTogetherCompo
1717
1818export type UseFrequentlyBoughtTogetherProps < TObject > = OptionalRecommendClient <
1919 GetFrequentlyBoughtTogetherProps < TObject >
20- > ;
20+ > & { enabled ?: boolean } ;
2121
2222export type FrequentlyBoughtTogetherProps <
2323 TObject
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ const UncontrolledRelatedProducts = createRelatedProductsComponent({
1515
1616export type UseRelatedProductsProps < TObject > = OptionalRecommendClient <
1717 GetRelatedProductsProps < TObject >
18- > ;
18+ > & { enabled ?: boolean } ;
1919
2020export type RelatedProductsProps < TObject > = UseRelatedProductsProps < TObject > &
2121 Omit <
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ const UncontrolledTrendingFacets = createTrendingFacetsComponent({
1515
1616export type UseTrendingFacetsProps < TObject > = OptionalRecommendClient <
1717 GetTrendingFacetsProps < TObject >
18- > ;
18+ > & { enabled ?: boolean } ;
1919
2020export type TrendingFacetsProps < TObject > = UseTrendingFacetsProps < TObject > &
2121 Omit <
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ const UncontrolledTrendingItems = createTrendingItemsComponent({
1515
1616export type UseTrendingItemsProps < TObject > = OptionalRecommendClient <
1717 GetTrendingItemsProps < TObject >
18- > ;
18+ > & { enabled ?: boolean } ;
1919
2020export type TrendingItemsProps < TObject > = UseTrendingItemsProps < TObject > &
2121 Omit <
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { useStableValue } from './useStableValue';
1212import { useStatus } from './useStatus' ;
1313
1414export 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 ,
Original file line number Diff line number Diff line change @@ -9,9 +9,12 @@ import { useAlgoliaAgent } from './useAlgoliaAgent';
99import { useStableValue } from './useStableValue' ;
1010import { useStatus } from './useStatus' ;
1111
12- export type UseRecommendationsProps < TObject > = GetRecommendationsProps < TObject > ;
12+ export type UseRecommendationsProps <
13+ TObject
14+ > = GetRecommendationsProps < TObject > & { enabled ?: boolean } ;
1315
1416export 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 ,
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { useStableValue } from './useStableValue';
1212import { useStatus } from './useStatus' ;
1313
1414export 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 ,
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { useAlgoliaAgent } from './useAlgoliaAgent';
1212import { useStatus } from './useStatus' ;
1313
1414export 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 ,
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { useStableValue } from './useStableValue';
1212import { useStatus } from './useStatus' ;
1313
1414export 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 ,
You can’t perform that action at this time.
0 commit comments