Skip to content
Discussion options

You must be logged in to vote

Hi @kboul, makeStyles in version 9 can be optimized at build time, which makes doing something like the above not possible since we wouldn't know the runtime value of someProp beforehand. What you can do for those cases is something like the following:

const useStyles = makeStyles({
  tableRowBase: {
    ...
  },
  backgroundColor1: {
    backgroundColor: 'oneColor'
  },
  backgroundColor2: {
    backgroundColor: 'otherColor'
  }
});

const MyComponent = (props) => {
  const styles = useStyles();
  const tableRowClassName = mergeClasses(styles.tableRowBase, props.someProp ? styles.backgroundColor1 : styles.backgroundColor2);
  ...
}

I hope that helps!

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@kboul
Comment options

@khmakoto
Comment options

@kboul
Comment options

@khmakoto
Comment options

Answer selected by kboul
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants