question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Weird interaction with react-router-redux

See original GitHub issue

I found that, when using handleActions and combineReducers alongside react-router-redux, the initial state coming out as { routing: [Object] }

Upon investigating further, handleActions will only return the initialState if the current state is undefined, but react-router-redux is setting it to { routing: [Object] }

react-router-redux triggers a dispatch with { type: '@@router/LOCATION_CHANGE' } as soon it’s loaded, and it happens before anything else, overwriting the original initialState that was set in handleActions, I’m having to manually set the initial state with a initialState action for this purpose.

It seems like a racing condition, but since react-router-redux always calls first, my initial state is always { routing: [Object] } (which is the state added by react-router-redux).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
pocesarcommented, Feb 11, 2017

after checking the source for redux-actions I noticed that the members of the parameter passed to handleActions aren’t exposed. I was expecting that the initialState members would be able to get passed to combineReducers like expected. if it would have it set to Object.defineProperty with enumerable true, it would work as intended (with the spread operator), like this:

let obj = function handleActions() { } 
Object.defineProperty(obj, 'ok', { enumerable: true, value: () => {} })

let anotherObject = { ok2: () => {} }
{
...obj,
anotherObj
}
// becomes { ok: () => {}, ok2: () => {} }  
// in the case of combineReducers({ ...obj, routing: routerReducer }) would have the proper keys passed to the combineReducers

I can make a PR for it to work out of the box if it’s interesting, otherwise I’ll just hack my away

0reactions
yangmillstheorycommented, Feb 12, 2017

If you can accomplish what you can without too much code, I’d just advise doing that. In your case, I guess I’d have a subreducer for access, export that, and use the standard convention of

import access from './access'

const rootReducer = combineReducers({ access, router })

Not sure where you get router from, but presumably from react-router-redux.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[10.0.0-rc1] Really weird issue with react-redux connect() #1864
The bug is that when the component is showing on a page and the store changes to make render() return null, the component...
Read more >
Strange behavior in react/redux - Stack Overflow
In my React/Redux app, I make a backend API call to create an entry in a calendar. This is initiated in my handler...
Read more >
Let the URL do the Talking, Part 1: The Pain of React Router ...
This is how most conversations about routing end in the React/Redux ecosystem. There's no doubt that React Router is the standard-bearer for ...
Read more >
So don't use Redux, React Router, and Thunks ... - Hacker News
on: My struggle to learn React. So don't use Redux, React Router, and Thunks. I don't even know what React JSS is. Use...
Read more >
Authenticated Routing with React, React Router, Redux ...
In this basic version of the log in page, implement the connect function from Redux, which consumes the store we'll pass down via...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found