Skip to content

Commit 90ddbd7

Browse files
committed
Client App with Ajax request
1 parent 6df1d22 commit 90ddbd7

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

client/app.jsx

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,49 @@
1-
import React from 'react';
1+
import React, {Component} from 'react';
22
import {render} from 'react-dom';
33
import {Router, browserHistory, Route} from 'react-router';
44

5+
class List extends Component {
6+
constructor(props) {
7+
super(props);
8+
this.state = {items: []};
9+
}
10+
11+
componentDidMount() {
12+
this.fetchList();
13+
}
14+
15+
fetchList() {
16+
fetch('http://jsonplaceholder.typicode.com/users')
17+
.then(res => {
18+
return res.json();
19+
})
20+
.then(data => {
21+
console.log(data);
22+
this.setState({
23+
items: data
24+
});
25+
})
26+
.catch(err => {
27+
console.log(err);
28+
});
29+
}
30+
31+
render() {
32+
return (
33+
<ul>
34+
{this.state.items.map(item => {
35+
return <li key={item.id}>{item.name}</li>;
36+
})}
37+
</ul>
38+
);
39+
}
40+
}
41+
542
const App = () => {
643
return (
744
<div>
845
<h2>React Universal App</h2>
46+
<List/>
947
</div>
1048
);
1149
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"esnext": true,
4141
"space": 2,
4242
"globals": [
43-
"document"
43+
"document",
44+
"fetch"
4445
],
4546
"extends": [
4647
"xo",

0 commit comments

Comments
 (0)