O'Reilly logo

Mastering React by Ryan Vice, Adam Horton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The posts store

At this point, the posts store allows fetching a single post or all of the posts in the system. This will be revised to fetch batches of posts in Chapter 9, React Blog App Part 4 – Infinite Scroll and Search, for the infinite scroll loading feature.

Here's the posts store source:

File: js/stores/posts.js

import Reflux from 'reflux'; import Actions from 'appRoot/actions'; import Request from 'superagent'; import Config from 'appRoot/appConfig'; export default Reflux.createStore({ listenables: Actions, endpoint: Config.apiRoot + '/posts', posts: [], // called when mixin is used to init the component state getInitialState: function () { return this.posts; }, init: function () { Request .get(this.endpoint) .end(function (err, res) { ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required