Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Pure React components with Redux and react-router
store.subscribe(() => {
<Router history={browserHistory}>
// Note the use of onEnter event
<Route path="/chunk/:id" onEnter={handleEnterChunk} component={attachState(ChunkPage.Chunk,'chunk')}/>
// read route params (state.params) and do required state changes
function handleEnterChunk(state,replace,callback) {
let chunkP = blackstar.get({ids:[state.params['id']]});
let tagsP = blackstar.getAllTags();
Promise.all([chunkP,tagsP]).then(([chunks,tags]) => {
const action = {
type: ChunkPage.actionTypes.LOADED_CHUNK,
chunk: _.find(chunks, (item:any) => === state.params['id']),
allTags: tags
// populate on `Component` with the state for that component
var attachState = function(Component, reducerName) {
return React.createClass({
render: function() {
return React.createElement(Component, _.extend({
data: store.getState()[reducerName],
dispatch: enhancedDispatcher
}, this.props));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment