-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
45 lines (40 loc) · 1.12 KB
/
App.js
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
import React, { useState } from 'react';
import collections from './collections';
import MenuItem from './Components/MenuItem';
import CategoryItem from './Components/CategoryItem';
const showAllCategories = [
'All',
...new Set(collections.map((item) => item.category)),
];
function App() {
const [menu, setMenu] = useState(collections);
const [categories, setCategories] = useState(showAllCategories);
const [index, setIndex] = useState([]);
const filterShirt = (category) => {
if (category === 'All') {
// update
setMenu(collections);
return;
}
// originally filter
const newFilter = collections.filter((item) => item.category === category);
// update
setMenu(newFilter);
};
return (
<main class='section' transition-style='in:circle:center'>
<div className='main-title'>
<h2>best popular</h2>
{categories[index]}
</div>
<div className='menu'>
<CategoryItem
showAllCategories={showAllCategories}
filterShirt={filterShirt}
/>
<MenuItem menu={menu} />
</div>
</main>
);
}
export default App;