Skip to content

Commit

Permalink
feat: return object from useRecommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed May 11, 2021
1 parent 565bb83 commit bcecce9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/react-recommendations/src/Recommendations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function defaultRender<TObject>(props: {
export function Recommendations<TObject extends ProductRecord>(
props: RecommendationsProps<TObject>
) {
const recommendations = useRecommendations<TObject>(props);
const { recommendations } = useRecommendations<TObject>(props);
const render = props.children || defaultRender;

const children = (
Expand Down
10 changes: 8 additions & 2 deletions packages/react-recommendations/src/useRecommendations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export type UseRecommendationsProps = {
threshold?: number;
};

type UseRecommendationReturn<TObject> = {
recommendations: TObject[];
};

function getDefaultedProps(
props: UseRecommendationsProps
): InternalUseRecommendationsProps {
Expand All @@ -46,7 +50,7 @@ function getDefaultedProps(

export function useRecommendations<TObject extends ProductRecord>(
userProps: UseRecommendationsProps
): TObject[] {
): UseRecommendationReturn<TObject> {
const [products, setProducts] = useState<TObject[]>([]);
const props = useMemo(() => getDefaultedProps(userProps), [userProps]);

Expand Down Expand Up @@ -97,5 +101,7 @@ export function useRecommendations<TObject extends ProductRecord>(
});
}, [props]);

return products;
return {
recommendations: products,
};
}

0 comments on commit bcecce9

Please sign in to comment.