blob: 5393d7d354ba07542599b2fbd2ff6d8a927e3357 (
plain) (
blame)
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
|
import 'whatwg-fetch';
import React from 'react';
import Message from './Message';
import Spinner from './Spinner';
export default class Thread extends React.Component {
constructor(props) {
super(props);
this.state = {
replies: [],
loading: false
};
}
componentDidMount() {
this.loadReplies();
}
loadReplies() {
this.setState({ replies: []})
const { mid } = this.props.match.params;
const url = `https://api.juick.com/thread?mid=${mid}`;
fetch(url)
.then(response => {
return response.json()
})
.then(data =>
this.setState({ replies: data })
).catch(ex => {
console.log(ex);
});
}
render() {
return this.state.replies && this.state.replies.length > 0 ? (
<Message data={this.state.replies[0]}/>
) : (
<Spinner />
);
}
}
|