在React JS redux中一起使用compose()和connect() [英] Using compose() and connect() together in React JS redux
问题描述
我开始使用React JS开发一个Web应用程序.我从主题森林购买了一个主题.在主题中,他们在组件中使用了像这样的撰写.
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的connect功能.
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屋!