Bagaimana cara menggunakan connect() dan withStyles() untuk komponen kelas di React?

const useStyles = makeStyles(theme => ({...});
const styles = useStyles();

class MyComponent extends React.Component {
    ...

    render() {
      return(<div className={...}>Stackoverflow</div>)
    }
}

const mapStateToProps = state => ({...});

export default connect(mapStateToProps, null)(withStyles(styles)(MyComponent))
0
Almaz Kaliev 30 Oktober 2019, 12:16

1 menjawab

Jawaban Terbaik

Anda perlu menggunakan compose juga

import { bindActionCreators, compose } from 'redux';

export default compose(
  connect(
    mapStateToProps,
    mapDispatchToProps, // or put null here if you do not have actions to dispatch
  ),
  withStyles(styles),
)(YourComponent);
3
Lazar Nikolic 30 Oktober 2019, 09:19