forked from ehangehang/mangkir-abp-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp.txt
57 lines (51 loc) · 1.48 KB
/
temp.txt
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
import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap/dist/js/bootstrap.bundle.min';
import React, { useState, useEffect } from 'react';
import { Link } from 'react-router-dom';
export class Home extends React.Component {
constructor(props) {
super(props);
this.state = {
data: [],
error: null,
isLoaded: false
};
}
componentDidMount() {
this.setState({ isLoading: true });
fetch('http://127.0.0.1:8000/api/recipes')
.then(response => response.json())
.then((result) => {
this.setState({
isLoaded: true,
data: result
});
},
(error) => {
this.setState({
isLoaded: true,
error
});
})
// .then(data => this.setState({ data: data }));
}
render() {
const { data, isLoaded, error } = this.state;
console.log(data);
if (error){
return <div>Error: {error.message}</div>;
}else if (!isLoaded){
return <div>Loading....</div>
}else{
return (
<ul>
{data.map(item => (
<li key={item.recipeID}>
<b>{item.judul}</b> {item.foto}
</li>
))}
</ul>
);
}
}
}