export function App() {
const { classes, cx } = useStyles({ "color": "primary" });
return (
<div className={classes.root}>
<div className={classes.child}>
The Background take the primary theme color when the mouse is
hover the parent.
</div>
<div className={cx(classes.child, classes.small)}>
The Background take the primary theme color when the mouse is
hover the parent. I am smaller than the other child.
</div>
</div>
);
}
const useStyles = makeStyles<
{ color: "primary" | "secondary" },
"child" | "small"
>()((theme, { color }, classes) => ({
"root": {
"padding": 30,
[`&:hover .${classes.child}`]: {
"backgroundColor": theme.palette[color].main
}
},
"small": {},
"child": {
"border": "1px solid black",
"height": 50,
[`&.${classes.small}`]: {
"height": 30
}
}
}));
withStyles
SSR
With server side rendering enabled you could end up with warnings like:
Warning: Prop className did not match. Server: "tss-XXX-root-ref" Client: "tss-YYY-root-ref".
You can fix this error by providing an uniq id when calling makeStyles or withStyles (It will set XXX and YYY).
WARNING: Nested selectors requires support which .
It can't be polyfilled ( 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.