Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React redux connect with with styles and withrouter

I am trying to use connect in redux react as

Connect (mapstate.., mapdis..) (withstyles(dashboardstyle)(dashboard)

The above works fine but I need to add withRouter as well. Below change gives error Connect (mapstate.., mapdis..) (withstyles(dashboardstyle), withrouter(dashboard))

Whenever I add it gives exception such as cannot use class as a function. Any ideas how this can be fixed

like image 659
LearningPhase Avatar asked Oct 15 '18 19:10

LearningPhase


1 Answers

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))
like image 152
kasho Avatar answered Sep 20 '22 11:09

kasho