为什么我不能应用 redux 的 connect with material-ui withStyles?

Why I can't apply redux's connect with material-ui withStyles?

我正在尝试通过 'recompose' 中的 { compose } 函数在具有 connect() 函数的 redux 容器组件中添加来自 material-ui 的 withStyles() 挂钩,并且从重组包中得到这个错误:

TypeError: Function.prototype.apply 在 # 上被调用,它是一个对象而不是一个函数

我请求任何帮助,我已经在这上面花了太多时间


import { withStyles } from '@material-ui/core/styles';
import { styles } from './styles';
import { compose } from 'recompose';
import { connect } from 'react-redux';

...

function mapStateToProps(state) {
  return {
    someVal: state.someVal,
  }
}

function mapDispatchToProps(dispatch) {
  return ({
    changeVal: () => {dispatch('CHANGE_VAL')}
  })
}

export default compose(
  withStyles(styles),
  connect(mapStateToProps, mapDispatchToProps)(App)
);


//if i do:

export default connect(mapStateToProps,mapDispatchToProps)(App)

//or:

export default withStyles(styles)(App)

//it's work. (just to clarify)

connectwithStyles 都是 HOC

a higher-order component is a function that takes a component and returns a new component.

所以你需要把App包在withStylesconnect

里面
export default connect(mapStateToProps,mapDispatchToProps)(withStyles(styles)(App))