React Material UI - 导出多个高阶组件 [英] React Material UI - Export multiple higher order components
本文介绍了React Material UI - 导出多个高阶组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直坚持使用 redux 连接器导出 material-ui 样式.这是我的代码:
I'm stuck on exporting material-ui styles with redux connector. Here is my code:
import React, { Component } from 'react';
import { connect } from 'react-redux';
import Drawer from 'material-ui/Drawer';
import { withStyles } from 'material-ui/styles';
import PropTypes from 'prop-types';
const mapStateToProps = state => ({});
const reduxConnector = connect(mapStateToProps, null);
const styles = theme => {
console.log(theme);
return ({
paper: {
top: '80px',
boxShadow: theme.shadows[9]
},
});
};
class Cart extends Component {
render() {
const { classes } = this.props;
return (
<Drawer
open
docked
anchor="right"
classes={{ paper: classes.paper }}
>
<p style={{ width: 250 }}>cart</p>
</Drawer>
);
}
}
export default withStyles(styles, {name: 'Cart'})(Cart);
export default reduxConnector(Cart); // I want to add this
我试过了:
export default reduxConnector(withStyles(styles))(Cart); // return Uncaught TypeError: Cannot call a class as a function
export default withStyles(styles, {name: 'Cart'})(reduxConnector(Cart)); // return Uncaught Error: Could not find "store" in either the context or props of "Connect(Cart)". Either wrap the root component in a <Provider>, or explicitly pass "store" as a prop to "Connect(Cart)".
有什么解决办法吗?
推荐答案
install npm install recompose
或 yarn add recompose
install npm install recompose
or yarn add recompose
以及您的导出部分
export default compose(
withStyles(styles, {
name: 'App',
}),
connect(),
)(AppFrame);
我忘了导出我的商店.
这篇关于React Material UI - 导出多个高阶组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文