![](/img/trans.png)
[英]How can I export a react material-ui component with 2 styles object? (material-ui V1)
[英]Material UI v1 with Redux - How to export
我试图利用材料的UI V1与显示stajuan的终极版-佐贺登录模板这里 。 所以,我想合并这两个的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);
上面代码的最后两行注释掉的行是我的案例中要合并的语句。
你需要安装npm install recompose
或yarn add recompose
并在您的出口部分
export default compose(
withStyles(styles, {
name: 'App',
}),
connect(),
)(AppFrame);
或者你可以这样做:
export default withStyles(styles)(connect(select)(Cart));
您将能够使用密钥访问
this.props.domain
添加以下行以导出您的课程
const mapStateToProps = state => {
return { domain : 'yourdomain.com'
}
}
export default withStyles(styles)(connect(mapStateToProps)(Login));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.