How does `selectLocationState` work? Give examples
wzup opened this issue · 3 comments
Can you elaborate on that? It is not clear
selectLocationState - (default state => state.routing) A selector function to obtain the history state from your store. Useful when not using the provided routerReducer to store history state. Allows you to use wrappers, such as Immutable.js.
You say A selector function to obtain the history state. Ok, here's your function. But what to do with it? It throws. Give some examples.
const history = syncHistoryWithStore(browserHistory, store, {selectLocationState: (state) => {
// I have state here. What's next?
}});
It's an opportunity to select the location from state if you don't use the provided reducer, or it stores in state in a way the default selector won't work.
@timdorr
Can you provide example?
Your docs are obscure and examples provided in docs throw
const history = syncHistoryWithStore(browserHistory, store, {selectLocationState: (state) => {
return state.routing;
}});
// These both options throw
let rootReducer = reduceReducers(
// This throws
combineReducers({
routing: routerReducer,
}),
reducerA,
reducerB,
// This also throws
(state = {'locationBeforeTransitions': null}, {type, payload}) => {
if (type === 'LOCATION_CHANGE') {
return state.locationBeforeTransitions = payload;
}
return state
}
)Error
Uncaught Error: Expected the routing state to be available either as
state.routingor as the custom expression you can specify asselectLocationStatein thesyncHistoryWithStore()options. Ensure you have added therouterReducerto your store's reducers viacombineReducersor whatever method you use to isolate your reducers.