Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material UI v1 with Redux - How to export

I am trying to make use of Material-UI v1 with stajuan's Redux-Saga Login template shown here. So, I want to merge the export default thing of those two, in other words combine two functions for exporting the default class:

import React, {Component} from 'react';
import { connect } from 'react-redux';
import { withStyles, createStyleSheet } from 'material-ui/styles';

// Redux
function select (state) {
    return {
    data: state
    }
}

// Material UI v1
const styleSheet = createStyleSheet(theme => ({
    // ...
}));

// Class to be exported
class Login extends Component {
    // ...
    render () {
        // ...
    }

}

// H O W   T O   M E R G E   T H O S E ? ? ?
// export default connect(select)(Login);
// export default withStyles(styleSheet)(Login);

The last two commented-out lines of the code above are the statements to be combined in my case.

like image 229
vahdet Avatar asked Aug 14 '17 22:08

vahdet


2 Answers

you need to install npm install recompose or yarn add recompose

and on your export section

export default compose(
    withStyles(styles, {
        name: 'App',
    }),
    connect(),
)(AppFrame);

or you can do:

export default withStyles(styles)(connect(select)(Cart));

like image 147
ssuhat Avatar answered Sep 29 '22 13:09

ssuhat


You will be able to access with the key

this.props.domain

Add below line to export your class

const mapStateToProps = state => {
    return { domain : 'yourdomain.com'
    }
}
export default withStyles(styles)(connect(mapStateToProps)(Login));
like image 40
Pranav Avatar answered Sep 29 '22 12:09

Pranav