-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
58 lines (50 loc) · 1.54 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
46
47
48
49
50
51
52
53
54
55
56
57
58
import { BrowserRouter,Route,Routes } from "react-router-dom";
import Footer from "./components/Footer/Footer";
import Home from "./pages/Home/Home";
import AddTecnoProduct from "./pages/AddTecnoProduct/AddTecnoProduct";
import Contact from "./pages/Contact/Contact";
import TecnoProductList from "./pages/TecnoProductList/TecnoProductList";
import Menu from "./components/Menu/Menu";
import { useState,useEffect } from "react";
import axios from "axios";
function App() {
const [products, setProducts] = useState(
()=> {
const savedProducts = localStorage.getItem("products")
return savedProducts? JSON.parse(savedProducts) : []
}
)
// console.log(products)
const getProducts = async () => {
const URL = "https://66140aa62fc47b4cf27b7326.mockapi.io/Tecno-products"
try{
const res = await axios(URL)
const {data} = res
// console.log(data)
setProducts(data)
}catch(err) {
console.log(err)
}
}
useEffect(()=> {
localStorage.setItem("products", JSON.stringify(products))
})
useEffect(() => {
getProducts()
}, [])
return (
<div className="App">
<BrowserRouter>
<Menu/>
<Routes>
<Route path="/" element={<Home/>}/>
<Route path="/addTecnoProduct" element={<AddTecnoProduct getProducts={getProducts}/>}/>
<Route path="/contact" element={<Contact/>}/>
<Route path="/tecnoProductList" element={<TecnoProductList products={products} getProducts={getProducts}/>}/>
</Routes>
<Footer/>
</BrowserRouter>
</div>
);
}
export default App;