-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathPostList.js
33 lines (23 loc) · 967 Bytes
/
PostList.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
var createReactClass = require('create-react-class')
var DOM = require('react-dom-factories')
var db = require('./db')
var div = DOM.div, h1 = DOM.h1, ul = DOM.ul, li = DOM.li, a = DOM.a
// This is the component we use for listing the posts on the homepage
module.exports = createReactClass({
// Each component declares an asynchronous function to fetch its props.data
statics: {
fetchData: db.getAllPosts,
},
render: function() {
return div(null,
h1(null, 'Grumblr'),
// props.data will be an array of posts
ul({children: this.props.data.map(function(post) {
// If the browser isn't JS-capable, then the links will work as per
// usual, making requests to the server – otherwise they'll use the
// client-side routing handler setup in the top-level App component
return li(null, a({href: '/posts/' + post.id, onClick: this.props.onClick}, post.title))
}.bind(this))})
)
},
})