alexnm / re-ducks

An attempt to extend the original proposal for redux modular architecture: https://github.com/erikras/ducks-modular-redux

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Where does the content of the mapDispatchToProps go?

caedes opened this issue · comments

Hi!

I'm just wondering where I can put mapDispatchToProps of the ⚛️Redux connect. I want to unit test it, and can't just write it down as:

import { connect } from 'react-redux';

import MyComponent from './component';
import { actions, selectors } from './redux';

return connect(selectors.adSenseOptions, {
  myAction: actions.myAction01
})(MyComponent);

Maybe it makes sense to put it into the selectors.js, because it is a selection of some of the actions.

import { connect } from 'react-redux';

import MyComponent from './component';
import { actions, selectors } from './redux';

return connect(selectors.adSenseOptions, ...actions)(MyComponent);

What do you think?

I wouldn't introduce a dependency from the components to the state management layer. Testing the component without the connect function is a bit of a problem. I suggest you either export both the "connected" component as well as the regular component, so you can unit test it separately.