【发布时间】:2018-12-18 07:18:55
【问题描述】:
我开始使用 React JS 开发 Web 应用程序。我从主题森林买了一个主题。在主题中,他们在组件中使用了这样的 compose。
...Other code here
Login.propTypes = {
classes: PropTypes.shape({}).isRequired,
width: PropTypes.string.isRequired
};
export default compose(withWidth(), withStyles(themeStyles, { withTheme: true }))(Login);
正如您所见,他们的代码在导出组件时最后使用了 compose。我无法修改他们的内置结构。我现在喜欢做的是我也喜欢使用 react 的连接功能。
通常使用 connect 代替 compose。现在,如果我想使用 connect 来处理应用程序的状态,如何将它与 compose 一起使用?
【问题讨论】:
-
您可以尝试以下方法:
export default compose(withWidth(), withStyles(styles, {withTheme: true}), connect(mapStateToProps, mapDispatchToProps))(Login); -
这是什么意思?它从哪里获得道具?使用 props 调用此组件将使用给定的 props 调用 Login 组件,然后调用 withStyles() 和 withWidth() ?这一切我还是有点迷茫
标签: reactjs redux react-redux recompose