0

我正在使用 react material design 和 redux 并且我有一个类组件。我正在尝试向 rmd 快速拨号组件添加一些自定义样式,这是我的组件:

import React, { Component } from 'react';
import { connect } from 'react-redux';
import { withStyles, makeStyles } from '@material-ui/core/styles';
import { SpeedDial, SpeedDialIcon, SpeedDialAction } from '@material-ui/lab';

const useStyles = makeStyles((theme) => ({
    speedDial: {
        position: 'absolute'
      }
}));

const actions = [...]

class ToolBar extends Component {

    render() {
        let { classes } = this.props;
        return (
            <SpeedDial
                ariaLabel="SpeedDial Tools"
                icon={<SpeedDialIcon />}
                className={classes.speedDial}
                open={this.state.open}>
                {actions.map((action) => (
                    <SpeedDialAction
                        key={action.name}
                        icon={action.icon}
                        tooltipTitle={action.name}
                    />
                ))}
            </SpeedDial>
        )
    }
}

const mapStateToProps = state => ({...})
export default connect(mapStateToProps, null)(withStyles(useStyles)(ToolBar))

我已经根据 rmd 文档为主题配置完成了所有其他事情,但这是我得到的结果: 在此处输入图像描述

将添加该类,但 css 无法正确呈现

4

2 回答 2

0

通过这些更改可以正常工作:

const styles = theme => ({
    speedDial: {
        position: 'absolute'
    }
});

和 :

export default connect(mapStateToProps, null)(withStyles(styles, { withTheme: true })(ToolBar))
于 2020-05-06T18:31:53.367 回答
0

你不应该使用类组件和材质 UI,你应该将你的组件重构为功能。

于 2020-05-06T18:09:15.803 回答