React Material UI - Export multiple higher order components

后端 未结 7 1441
深忆病人
深忆病人 2020-12-04 15:43

I\'m stuck on exporting material-ui styles with redux connector. Here is my code:

import React, { Component } from \'react\';
import { connect } from \'react         


        
7条回答
  •  醉话见心
    2020-12-04 15:57

    Take a look at how it's being handled in the material-ui docs site, specifically in the AppFrame component:

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

    They're using recompose to do this.

    So in your case, it would be:

    import React, { Component } from 'react';
    import compose from 'recompose/compose';
    import { connect } from 'react-redux';
    import Drawer from 'material-ui/Drawer';
    import { withStyles } from 'material-ui/styles';
    import PropTypes from 'prop-types';
    
    const styles = theme => {
      console.log(theme);
      return {
        paper: {
          top: '80px',
          boxShadow: theme.shadows[9],
        },
      };
    };
    
    const Cart = ({ classes }) =>
      
        

    cart

    ; const mapStateToProps = state => ({}); export default compose( withStyles(styles, { name: 'Cart' }), connect(mapStateToProps, null) )(Cart);

提交回复
热议问题