【问题标题】:Material UI v1 with Redux - How to export带有 Redux 的 Material UI v1 - 如何导出
【发布时间】:2018-01-22 20:37:36
【问题描述】:

我正在尝试将Material-UI v1 与显示为here 的stajuan 的Redux-Saga 登录模板一起使用。所以,我想合并这两者的export default,换句话说,结合两个函数来导出默认类:

import React, {Component} from 'react';
import { connect } from 'react-redux';
import { withStyles, createStyleSheet } from 'material-ui/styles';

// Redux
function select (state) {
    return {
    data: state
    }
}

// Material UI v1
const styleSheet = createStyleSheet(theme => ({
    // ...
}));

// Class to be exported
class Login extends Component {
    // ...
    render () {
        // ...
    }

}

// H O W   T O   M E R G E   T H O S E ? ? ?
// export default connect(select)(Login);
// export default withStyles(styleSheet)(Login);

上面代码的最后两行注释掉的是我的例子中要合并的语句。

【问题讨论】:

标签: javascript reactjs ecmascript-6 react-redux material-ui


【解决方案1】:

你需要安装npm install recomposeyarn add recompose

在您的导出部分

export default compose(
    withStyles(styles, {
        name: 'App',
    }),
    connect(),
)(AppFrame);

或者你可以这样做:

export default withStyles(styles)(connect(select)(Cart));

【讨论】:

    【解决方案2】:

    您将能够使用密钥访问

    this.props.domain
    

    添加以下行以导出您的课程

    const mapStateToProps = state => {
        return { domain : 'yourdomain.com'
        }
    }
    export default withStyles(styles)(connect(mapStateToProps)(Login));
    

    【讨论】:

      猜你喜欢
      • 2018-12-16
      • 1970-01-01
      • 2018-08-03
      • 1970-01-01
      • 1970-01-01
      • 2018-09-10
      • 1970-01-01
      • 2017-11-18
      • 1970-01-01
      相关资源
      最近更新 更多