如何在React中为类组件使用connect()和withStyles()?
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 :(得分:1)
您还需要使用compose
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);