blob: 52f3507606e9f6cebc5a88ce82873fc8af0c08fd (
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
|
import "whatwg-fetch"
import React, {PropTypes} from "react"
import ReactDOM from "react-dom"
import Message from "./components/Message.jsx"
const Page = React.createClass({
getInitialState() {
return {msgs: [], loading: false}
},
propTypes: {
msgs: PropTypes.array,
source: PropTypes.string.isRequired
},
render() {
var nodes = this.state.msgs.map(msg => {
return (<Message key={msg.mid} mid={msg.mid} user={msg.user} body={msg.body} timestamp={msg.timestamp}/>)
});
return (<div className="msgs">{nodes}</div>)
},
componentDidMount() {
fetch(this.props.source)
.then(response => {
return response.json()
})
.then(data =>
this.setState({ msgs: data })
).catch(ex => {
console.log(ex)
});
}
});
ReactDOM.render(<Page source="https://api.juick.com/messages" />, document.getElementById("content"));
|