-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAPIDataList.js
38 lines (32 loc) · 864 Bytes
/
APIDataList.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
//npm install axios
import React, { Component } from 'react';
class TodoList extends Component {
constructor(props) {
super(props);
this.state = {
todos: []
};
}
componentDidMount() {
axios.get("api endpoint route")
.then(response => this.setState({ todos: response.data }))
}
render() {
const { todos } = this.state;
return (
<div className="container">
<div className="row">
<div className="col-lg-8 offset-lg-2">
<h2>Todo List</h2>
{todos.map((todo, index) => (
<div key={index}>
<p> {todo.body}</p>
</div>
))}
</div>
</div>
</div>
);
}
}
export default TodoList;