πŸ’«Nested selectors (ex $ syntax)

tss-react unlike jss-react doesn't support the $ syntax but is a better alternative.

With the Modern API and makeStyles API

In JSS you can do:

//WARNING: This is legacy JSS code!
{
  parent: {
      padding: 30,
      "&:hover $child": { // <- This do not work in TSS
          backgroundColor: "red"
      },
  },
  child: {
      backgroundColor: "blue"
  }
}
//...
<div className={classes.parent}>
    <div className={classes.child}>
        Background turns red when the mouse is hovering over the parent
    </div>
</div>

This is how you would achieve the same result with tss-react

Another example:

The render of the above code

WARNING: Nested selectors requires ES6 Proxy support which IE doesn't support. It can't be polyfilled (this will not work) but don't worry, if Proxy is not available on a particular browser, no error will be thrown and TSS will still do its work. Only nested selectors won't work.

withStyles

SSR

NOTE: This does not apply to the Modern API, only for makeStyles and withStyles

In SSR setups, on stylesheets using nested selectors, you could end up with warnings like:

Example of error you may run against with Next.js

You can fix this error by providing a unique id when calling makeStyles or withStyles (It will set XXX and YYY).

Short unique identifiers can be generated with this website.

withStyles:

Last updated

Was this helpful?