小编典典

在React JS redux中一起使用compose()和connect()

reactjs

我开始使用React JS开发一个Web应用程序。我从主题森林购买了一个主题。在主题中,他们在组件中使用像这样的撰写。

...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功能。

通常connect用于代替撰写。现在,如果我想使用connect来处理应用程序的状态,如何将其与compose一起使用?


阅读 431

收藏
2020-07-22

共1个答案

小编典典

const enhance = compose(
    withRouter,
    withStyles(styles, 'some style'),
    connect(mapStateToProps, mapDispatchToProps),
    ....

export default enhance(MyComponent);
2020-07-22