我一直在用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);

我忘了出口我的store .

Reactjs相关问答推荐

尽管在CLI中收到来自Stripe的OK Post请求,但没有webhook Post请求的处理- NextJS 14

未捕获的类型错误:类型Orbitum创建者未定义

如何使用React防止并发注册并处理Firestore数据库中的插槽可用性

使用useEffect挂钩获取数据

从`redux—thunk`导入thunk `在stackblitz中不起作用

在react中向数组状态添加值时出错

在Reaction+Redux+RTKQuery中对API调用进行排序

如何在重新图表中更改悬停时的条形填充 colored颜色 ?

我想删除NextJs中的X轴标签APEXCHARTS

阻止组件更新的多分派Redux Thunk或setState是否有任何问题

状态改变不会触发重新渲染

在 React 中,为什么不将组件和钩子结合起来呢?

Mui 在 TextField 标签上添加工具提示显示两个工具提示框

Mui / Material UI 5:如何从 StaticTimePicker 中删除打开下一个视图/打开上一个视图按钮?

REACT: UseState 没有更新变量(ant design 模态形式)

useRef 不关注模态

如何在PrimeReact的表格中修改筛选图标功能

如何避免在 react useEffect 上滚动时出现小的延迟?

不能在我的代码中使用 .给我一个警告!有人知道解决方案吗?

使用输入类型文本对 useState 和日期做出react