React-redux: be able to pass undefined or null as mapStateToProps

Created on 7 Mar 2016  路  1Comment  路  Source: reduxjs/react-redux

Hello

I often need to connect only actions to my component. So I write:

@connect(
  ()=>{return{}},
  (dispatch) => {
    return {
      actions: bindActionCreators(informationActions, dispatch)
    };
  }
)

I read in documentation:

mapStateToProps(state, [ownProps]): stateProps: If specified, the component will subscribe to Redux store updates. Any time it updates, mapStateToProps will be called. Its result must be a plain object*, and it will be merged into the component鈥檚 props. If you omit it, the component will not be subscribed to the Redux store. If ownProps is specified as a second argument, its value will be the props passed to your component, and mapStateToProps will be re-invoked whenever the component receives new props.

"If specified" lets me think we can use connect() without defining mapStateToProps

So I tried:

@connect(null,
  (dispatch) => {
    return {
      actions: bindActionCreators(informationActions, dispatch)
    };
  }
)

But it didn't work. it makes sens to be able to connect actions only, isn't it? Is there a better way than writing ()=>{return{}}? Otherwise I can try to implement it in React-Redux. Let me know.

Most helpful comment

Actually it works... a side effect from another connect() triggered my issue. My bad!

>All comments

Actually it works... a side effect from another connect() triggered my issue. My bad!

Was this page helpful?
0 / 5 - 0 ratings