Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested class in another selected class with makeStyles

I need to know how to target 'element' when root is selected

This is makeStyles:

const useStyles = makeStyles(theme => ({
   root:{
      '&.selected': {
      }
   },
   element: {
   }
})

This is jsx

<div className={`${classes.root} ${elementSelected ? 'selected : ''}`}>
  <div className={classes.element}>
  </div>
</div>
like image 777
Aladdin Mhemed Avatar asked Dec 18 '19 00:12

Aladdin Mhemed


Video Answer


1 Answers

You can use https://www.npmjs.com/package/classnames to achieve this.

const useStyles = makeStyles(theme => ({
   root:{
      '&.selected $element': {
      }
   }
})

And your JSX

import classNames from 'classnames';

...

<div className={classNames(classes.root, elementSelected ? 'selected : '')}>
  <div className={classes.element}>
  </div>
</div>
like image 101
Chris Chen Avatar answered Sep 26 '22 05:09

Chris Chen