React Material UI-导出多个高阶组件

我一直坚持使用redux连接器导出Material-ui样式。这是我的代码:

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)".

有什么办法吗?

回答:

安装npm install recomposeyarn add recompose

在您的出口部分

export default compose(

withStyles(styles, {

name: 'App',

}),

connect(),

)(AppFrame);

我忘了出口我的商店。

以上是 React Material UI-导出多个高阶组件 的全部内容, 来源链接: utcz.com/qa/400586.html

回到顶部