acdlite / redux-router

Redux bindings for React Router – keep your router state inside your Redux store
MIT License
2.3k stars 200 forks source link

Router State === null & Nested object madness & Initial State #156

Closed igl closed 8 years ago

igl commented 8 years ago

Having the initial state of the redux-router-reducer generate null until the @routerDidChange action fires makes using the values in a mapStateToProps function rather ugly.

({router}) => ({
    searchTerm : router.location.query.term
})

has to be:

({router}) => ({
    searchTerm : router? (router.location? (router.location.query? router.location.query.term : '') : '' ) : ''
})

How can i avoid this?

mikebarnhardt commented 8 years ago

Would also like a resolution to this problem as mapStateToProps is being called twice on every page load due to @@reduxReactRouter/routerDidChange.

Scarysize commented 8 years ago

@MikeBarnhardt this was fixed by #183 @igl what would you prefer?

something like function routerStateReducer(state = { routes: [], params: null, location: null, components: [], }, action) {..}

igl commented 8 years ago

I use a custom store-enhancer now. I can't disable page transition in the dev-tools but all other headaches are gone and the simplicity of 45 lines vs redux-router is worth it.

Scarysize commented 8 years ago

@igi Great!

igl commented 8 years ago

https://gist.github.com/igl/23c8192a04b6251f3d60

mikebarnhardt commented 8 years ago

@Scarysize Thanks!