-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHome.jsx
More file actions
55 lines (48 loc) · 1.24 KB
/
Home.jsx
File metadata and controls
55 lines (48 loc) · 1.24 KB
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
import { useState } from "react";
const Home = () => {
const [loader, setLoader] = useState(false);
const [products, setProducts] = useState([]);
const fetchProduct = async () => {
try {
setLoader(true);
const res = await fetch("https://dummyjson.com/products");
const result = await res.json();
console.log(result)
setProducts(result?.products);
setLoader(false);
} catch(error) {
setLoader(false);
}
};
return (
<div>
<button onClick={fetchProduct}>Fetch Data</button>
{loader ? (
<div>
<img src="/Loading_icon.gif" />
</div>
) : (
products.map((pr) => {
console.log(pr); //
return (
<div>
<h6>{pr.title}</h6>
<div>
<span>Brand::</span> <span>{pr.brand}</span>
</div>
<div>
<span>Price::</span> <span>{pr.price}</span>
</div>
<a href="/cart" > Unmount
</a>
</div>
);
})
)}
</div>
);
};
export default Home;
// Dom => HTML dOM + CSS DOM => dom => browser painting
// Updating => re-rendering
// unmouting state