Skip to content

Instantly share code, notes, and snippets.

@jergason
Created October 29, 2014 21:08
Show Gist options
  • Save jergason/1b13929d32cff4f0e501 to your computer and use it in GitHub Desktop.
Save jergason/1b13929d32cff4f0e501 to your computer and use it in GitHub Desktop.
cursors woooo
var React = require('react');
var History = require('immutable-history');
// call `render` whenever the cursor changes
var state = new History({posts: [], username: 'Jamitron The Terrible'}, render);
var App = React.createClass({
render: function() {
var postsCursor = this.props.data.cursor(['posts']);
return <div>
<Posts posts={postsCursor} />
</div>
}
});
var Posts = React.createClass({
render: function() {
var posts = this.props.posts.map(function(p) {
return <li>Sup</li>;
});
return <ul>
{posts}
</ul>
}
});
function render(cursor) {
React.renderComponent(<App data={cursor} />, document.body);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment