在 React JS redux 中一起使用 compose() 和 connect() [英] Using compose() and connect() together in React JS redux
问题描述
我开始使用 React JS 开发 Web 应用程序.我从主题森林买了一个主题.在主题中,他们在组件中使用了这样的 compose.
I am starting to develop a web application using React JS. I bought a theme from theme forest. In the theme, they are using compose like this in the component.
...Other code here
Login.propTypes = {
classes: PropTypes.shape({}).isRequired,
width: PropTypes.string.isRequired
};
export default compose(withWidth(), withStyles(themeStyles, { withTheme: true }))(Login);
正如您所看到的,他们的代码在导出组件时使用了最后的 compose.我无法修改他们的建筑结构.我现在喜欢做的是我也喜欢使用 react 的连接功能.
As you can see their code is using the compose at the end when exporting the Component. I cannot modify their built-structure. What I like to do now is I like to use connect feature of the react as well.
通常用connect代替compose.现在,如果我想使用 connect 来处理应用程序的状态,我如何将它与 compose 一起使用?
Normally connect is used in the place of compose. Now, if I want to use connect to work with the state of the application, how can I use it together with compose ?
推荐答案
const enhance = compose(
withRouter,
withStyles(styles, 'some style'),
connect(mapStateToProps, mapDispatchToProps),
....
export default enhance(MyComponent);
这篇关于在 React JS redux 中一起使用 compose() 和 connect()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!