Search code examples
reactjsreduxmaterial-ui

React Material Design : using react material design custom style with redux in class component


I'm using react material design and redux and I've got a class component.I'm trying to add some custom styles to rmd speeddial component, here is my component:

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

I've done all the other things for theme configs according to rmd documentation BUT It's the result I get: enter image description here

The class will be added but the css won't render correctly


Solution

  • It works fine by these changes :

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

    and :

    export default connect(mapStateToProps, null)(withStyles(styles, { withTheme: true })(ToolBar))