Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions components/Pricing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ export default function Pricing({
products,
subscription
}: Props) {
const intervals = Array.from(
new Set(
products.flatMap((product) =>
product?.prices?.map((price) => price?.interval)
)
)
);
// const intervals = Array.from(
// new Set(
// products.flatMap((product) =>
// product?.prices?.map((price) => price?.interval)
// )
// )
// );
//ensure that these arrays are not undefined before calling the flatMap method.

const intervals = Array.from(new Set(products?.flatMap(product => product?.prices?.map(price => price?.interval))))

const router = useRouter();
const [billingInterval, setBillingInterval] =
useState<BillingInterval>('month');
Expand Down Expand Up @@ -72,7 +76,9 @@ export default function Pricing({
}
};

if (!products.length)
// To prevent error(undefined (reading 'length')), you should check if the products array exists and has a length before attempting to access its properties.

if (!products || products.length === 0)
return (
<section className="bg-black">
<div className="max-w-6xl px-4 py-8 mx-auto sm:py-24 sm:px-6 lg:px-8">
Expand Down