salvoravida/redux-first-history

location change action always dispatched on initial load

coopermaruyama opened this issue · 3 comments

While debugging why my app is re-rendering on initial load, I tracked it down to a location change action that is dispatched at this line:

https://github.com/salvoravida/redux-first-history/blob/master/src/create.ts#L90

I'm curious why this dispatch is needed? If it is to populate the initialState, could it not just be passed as initialState into createReducer in order to avoid this dispatch? Or is there some other reason I am unaware of?

Yes, you may have middlewares like redux-saga listening for LOCATION_CHANGE action "event," and the initial location is also a location change event.

@salvoravida is there a way to distinguish "initial location" vs "subsequent location changes", or to potentially include an option to disable this behavior? In all of my use-cases, I'm only interested in if the location changes via the user navigating around (and not initial page load)

I don't believe connected-react-router has this behavior, which caught me off guard trying to replace it
thanks for the library!

I don't believe connected-react-router has this behavior, which caught me off guard trying to replace it
thanks for the library!

It is configurable, as per the docs here:

In order to make this package more compatible with react-router-redux, a LOCATION_CHANGE action is dispatched for the initial location. This can however be disabled via the noInitialPop prop.

I'm in the same position, I don't want the initial load.