Skip to content

Commit 00469d4

Browse files
committed
List
1 parent e47063f commit 00469d4

File tree

4 files changed

+41
-47
lines changed

4 files changed

+41
-47
lines changed

React_Learning/06_List/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<meta
77
name="viewport"
88
content="width=device-width, initial-scale=1.0" />
9-
<title>Condition Rendering</title>
9+
<title>List</title>
1010
</head>
1111
<body>
1212
<div id="root"></div>

React_Learning/06_List/src/App.css

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +0,0 @@
1-
#root {
2-
max-width: 1280px;
3-
margin: 0 auto;
4-
padding: 2rem;
5-
text-align: center;
6-
}
7-
8-
.logo {
9-
height: 6em;
10-
padding: 1.5em;
11-
will-change: filter;
12-
transition: filter 300ms;
13-
}
14-
.logo:hover {
15-
filter: drop-shadow(0 0 2em #646cffaa);
16-
}
17-
.logo.react:hover {
18-
filter: drop-shadow(0 0 2em #61dafbaa);
19-
}
20-
21-
@keyframes logo-spin {
22-
from {
23-
transform: rotate(0deg);
24-
}
25-
to {
26-
transform: rotate(360deg);
27-
}
28-
}
29-
30-
@media (prefers-reduced-motion: no-preference) {
31-
a:nth-of-type(2) .logo {
32-
animation: logo-spin infinite 20s linear;
33-
}
34-
}
35-
36-
.card {
37-
padding: 2em;
38-
}
39-
40-
.read-the-docs {
41-
color: #888;
42-
}

React_Learning/06_List/src/App.jsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
import List from './List';
22

33
function App() {
4+
const fruits = [
5+
{ id: 1, name: 'Apple', calories: 90 },
6+
{ id: 2, name: 'banana', calories: 45 },
7+
{ id: 3, name: 'mango', calories: 105 },
8+
{ id: 4, name: 'coconut', calories: 159 },
9+
{ id: 5, name: 'pineapple', calories: 37 },
10+
];
11+
const vegatables = [
12+
{ id: 7, name: 'Potatos', calories: 105 },
13+
{ id: 8, name: 'celery', calories: 15 },
14+
{ id: 9, name: 'carrots', calories: 25 },
15+
{ id: 10, name: 'corn', calories: 63 },
16+
{ id: 11, name: 'broccoli', calories: 50 },
17+
];
418
return (
519
<>
6-
<List />
20+
<List
21+
items={fruits}
22+
category="fruits"
23+
/>
24+
<List
25+
items={vegatables}
26+
category="Vegatables"
27+
/>
728
</>
829
);
930
}

React_Learning/06_List/src/List.jsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
function List() {
2-
const fruits = ['Apple', 'banana', 'coconut', 'pineapple'];
3-
return fruits;
1+
function List(props) {
2+
const category = props.category;
3+
const itemList = props.items;
4+
5+
const listItems = itemList.map((item) => (
6+
<li key={item.id}>
7+
{item.id} ) &nbsp;
8+
{item.name}: &nbsp; {item.calories}
9+
</li>
10+
));
11+
return (
12+
<>
13+
<h1>
14+
<b>{category}</b>
15+
</h1>
16+
<ol>{listItems}</ol>
17+
</>
18+
);
419
}
520
export default List;

0 commit comments

Comments
 (0)