React className override #1491
Replies: 4 comments 12 replies
Made an example https://codesandbox.io/s/react-jss-playground-forked-3ww6e?file=/index.js Source order specificity is defined by the time when createUseStyles is called (module evaluated). In your case, you wanted Comp rule to override App rule but createUseStyles() of the Comp was called first. So I imported in the example App first, then Comp, so that Comp style have higher specificity. In other words, imports order is the same as style order in the DOM Imports:
DOM:
The last one always wins if other specificity properties are the same. You can achieve that also by moving the createUseStyles() call to a different place.
I recommend to not pass classes at all if possible, specificity issues like this can be avoided by simply not passing classes around. |
|
I solve it by managing index my self, managing index in hug project was complex for solving that I changed my components to atomic design pattern. |
|
I think the best solution for that is passing classes values to child components instead of give generate class name to child. So in the end merge them together and generate a class |

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Imagine a React component like this
But this is not working sometime, i think that is because of priority of CSS rules. How we could do something like this?
Reproduced: https://codesandbox.io/s/react-jss-playground-forked-ckehn?file=/com.js
All reactions