score:10

Accepted answer

You will need to install recompose:

npm i -s recompose

Then in your component:

import compose from 'recompose/compose'


export default compose(
   withStyles(styles),
   connect(mapStateToProps, mapDispatchToProps)
)(withRouter(Dashboard))

score:5

What's the return value of withStyles(styles)? I suspect it is a "Higher Order Component" (HOC), which is a function that expects to be passed the React component to wrap, and returns a React component. If that is the case, then you really want your call to look like this:

export default withStyles(styles)(
    connect(mapStateToProps, mapDispatchToProps)(withRouter(Dashboard))
)

That code is pretty ugly, though, and will rapidly get worse as you add in more HOCs, which is why the Recompose suggestion is a much better way to go. (But I wanted to add in some more context so that readers an understand what was causing the problem in the OP.)


Related Query

More Query from same tag