StoryShare API Handler
Initialize the API:
import Site from 'storyshare';
let s = new Site();
s.start()
.then(launchApp());
Dispatch a request using a tracking key:
componentWillMount() {
s.req('posts').track('newsfeed').read();
}
or with a promise once complete, to run further actions:
componentWillMount() {
s.req('posts').track('newsfeed').promise().read()
.then(posts => console.log('got some posts', posts));
}
Get the completion state, and the response content:
const mapStateToProps = (state) => ({
feedReady: s.getComplete('newsfeed'),
newsFeed: s.getResponse('newsfeed')
});
render() {
return this.props.feedReady ?
props.newsFeed.map(({ title, content }) => <div><h1>{ title }</h1><p>{ content }</p></div>)
<Spinner />;
}