-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
38 lines (36 loc) · 1.21 KB
/
App.js
File metadata and controls
38 lines (36 loc) · 1.21 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
import './App.css';
import Products from './components/Products';
import Cart from './components/Cart';
import { Route,Routes } from "react-router-dom";
import "./App.css"
import { useEffect, useState } from 'react';
function App() {
const [cart, setCart] = useState([]);
const [products, setProducts] = useState([]);
const [customData,setCustomData]=useState([]);
const [loading,setLoading]=useState(true);
const performAPICall = async () => {
try {
const response = await fetch("https://geektrust.s3.ap-southeast-1.amazonaws.com/coding-problems/shopping-cart/catalogue.json")
.then(res=>res.json()).then(data =>data)
setProducts(response);
setCustomData(response);
setLoading(false);
return response.data;
} catch (error) {
console.log(error);
}
};
useEffect(()=>{
performAPICall();
},[])
return (
<div className="App">
<Routes>
<Route path='/' element={<Products products={products} setProducts={setProducts} customData={customData} cart={cart} setCart={setCart} loading={loading}/>}/>
<Route path='/cart' element={<Cart cart={cart} setCart={setCart} customData={customData}/>}/>
</Routes>
</div>
);
}
export default App;