-
Notifications
You must be signed in to change notification settings - Fork 25
/
App.js
35 lines (32 loc) · 902 Bytes
/
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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0
import React, { useEffect, useState } from "react";
import ProductList from "./components/ProductList";
import config from "./config.json";
import axios from "axios";
const App = ({ isSSR, ssrData }) => {
const [err, setErr] = useState(false);
const [result, setResult] = useState({ loading: true, products: null });
useEffect(() => {
const getData = async () => {
const url = config.SSRApiStack.apiurl;
try {
let result = await axios.get(url);
setResult({ loading: false, products: result.data });
} catch (error) {
setErr(error);
}
};
getData();
}, []);
if (err) {
return <div>Error {err}</div>;
} else {
return (
<div>
<ProductList result={result} />
</div>
);
}
};
export default App;