reactjs - React redux 连接 with styles 和 withrouter

标签 reactjs react-redux router

我正在尝试在 redux React 中使用 connect

连接(mapstate..,mapdis..)(withstyles(dashboardstyle)(仪表板)

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

每当我添加时,它都会给出异常,例如不能将类用作函数。 任何想法如何解决这个问题

最佳答案

您需要安装 recompose:

npm i -s recompose

然后在你的组件中:

import compose from 'recompose/compose'


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

关于reactjs - React redux 连接 with styles 和 withrouter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52823456/

相关文章:

javascript - 当获取数据时对象最初为空然后被数据填充时如何处理对象

javascript - React、Axios 问题 : Response for preflight has invalid HTTP status code 401

angular - 如果使用查询参数,则以编程方式将查询参数附加到路由

node.js - 在node.js express中,默认路由器总是跳转到index.html静态文件

javascript - 删除处于 react 状态的数组的第一项

reactjs - SVG 以错误的颜色显示

javascript - 无法从 React 外部在 ReactJS 组件上设置 State

javascript - ReactJS,Redux : How do I return an array of items in my STATE?

javascript - 在课外访问 Prop

javascript - 我可以从 HTTP 请求中找到无线接入点的 BSSID(MAC 地址)吗?