blob: bfaf89127b40d44c4254625014afa25981b71b73 (
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
|
import "whatwg-fetch"
import React from "react"
import PropTypes from "prop-types"
import ReactDOM from "react-dom"
import Message from "./components/Message.jsx"
class Page extends React.Component {
constructor(props) {
super(props)
this.state = {msgs: [], loading: false}
}
render() {
var nodes = this.state.msgs.map(msg => {
return (<Message key={msg.mid} data={msg}/>)
});
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)
});
}
};
Page.propTypes = {
msgs: PropTypes.array,
source: PropTypes.string.isRequired
}
ReactDOM.render(<Page source="https://api.juick.com/messages" />, document.getElementById("content"));
|