本文介绍了React redux 与样式和路由器连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 redux react 中使用 connect 作为

I am trying to use connect in redux react as

连接 (mapstate.., mapdis..) (withstyles(dashboardstyle)(dashboard)

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

以上工作正常,但我还需要添加 withRouter.下面的变化给出了错误连接 (mapstate.., mapdis..) (withstyles(dashboardstyle), withrouter(dashboard))

The above works fine but I need to add withRouter as well.Below change gives errorConnect (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

推荐答案

您需要安装 recompose:

You will need to install recompose:

npm i -s recompose

然后在您的组件中:

import compose from 'recompose/compose'


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

这篇关于React redux 与样式和路由器连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 13:39
查看更多