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

标签 reactjs redux react-redux 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)".

有什么解决办法吗?

最佳答案

试试这个

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

其中 App 是您的组件。 对我来说效果很好。

关于reactjs - React Material UI - 导出多个高阶组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45704681/

相关文章:

reactjs - 如何将 createEntityAdapter 应用于 createApi 切片

reactjs - React-Redux - 未处理的拒绝(错误): Actions must be plain objects. 使用自定义中间件进行异步操作

mongodb - 处理 CRUD 应用程序中的重复值错误(react-redux + express-mongoose)

javascript - 尝试获取 <option> 的计数,因为它在 React 应用程序中被过滤掉了

reactjs - 管理 Azure 静态网站的 HTTP header

reactjs - React Native 中 child 如何继承 parent 的背景?

css - 使用 React 的多个 CSS 条件类

javascript - React + Redux HOC 加载器

javascript - 使用 validate.js 验证我的 TextInput 结果未定义

reactjs - 在 React/Redux 中更改异步操作完成时的路由