Material-ui: Can't pass props from state to styles when using withStyles

Created on 28 Dec 2017  路  2Comments  路  Source: mui-org/material-ui

With react-jss it's possible to do:

const styles = props => ({
  appContent: {
    position: 'absolute',
    left: props.sidebarOpen ? 240 : 0,
  }
})

const App = () => {...}

const mapStateToProps = createStructuredSelector({
  sidebarOpen: state => state.sidebar.open,
})

export default connect(mapStateToProps)(injectSheet(styles)(App))

It doesn't look like there's any way to pass the props to the styles using withStyles; all I can pass is the theme using withTheme. But in some components I may want to have the best of both worlds: props from state and the Material-UI theme. Why not support both in withStyles?

All 2 comments

Sigh, this is a nightmare so far. When I try to use dynamic styles with injectSheet it's SNAFU, generating class names with spaces in them like App- Unthemed- Dynamic-appFrame-4 App- Unthemed- Static-appFrame-1

Please ask JSS questions via the appropriate channels. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ericraffin picture ericraffin  路  3Comments

ghost picture ghost  路  3Comments

zabojad picture zabojad  路  3Comments

anthony-dandrea picture anthony-dandrea  路  3Comments

revskill10 picture revskill10  路  3Comments