-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.tsx
76 lines (69 loc) · 2.32 KB
/
page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* eslint-disable @next/next/no-img-element */
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { Container } from "@/components/ui/container";
import type { Metadata } from "next";
export const metadata: Metadata = {
title: "Without zod",
};
const getData = async () => {
const resp = await fetch("https://dummyjson.com/products?limit=5").then(
(res) => res.json(),
);
return resp;
};
export default async function Home() {
const data = await getData();
return (
<Card>
<CardHeader>
<CardTitle>Products</CardTitle>
<CardDescription>
Manage your products and view their sales performance.
</CardDescription>
</CardHeader>
<CardContent>
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 ">
{data.products.map(
(
product, // strict mode set to false, so no error here
) => (
<Card key={product.id}>
<CardHeader>
<CardTitle>{product.title}</CardTitle>
</CardHeader>
<CardContent>
<img
src={product.thumbnail}
alt={product.title}
className="w-full h-48 object-cover rounded-lg shadow-lg"
/>
<p className="font-bold mt-4 text-gray-800">
<span className="font-semibold">Price:</span> $
{product.cost}
</p>
<code className="text-xs bg-red-100 text-red-600 p-2 mt-2 rounded-md">
{"Price: {product.cost}"}
</code>
<div className="text-xs bg-red-100 text-red-600 p-2 mt-2 rounded-md">
{
"It uses the wrong key `cost`, it should be `price`. The value of `cost` is undefined, so it will show as `Price: $undefined`. No error will be thrown. However, you need to throw an error if the key is not found"
}
</div>
<p className="mt-2 text-sm text-gray-600">
{product.description}
</p>
</CardContent>
</Card>
),
)}
</div>
</CardContent>
</Card>
);
}