[styles] makeStyles + @media + Adapting based on props: not updating correctly
See original GitHub issue- The issue is present in the latest release.
- I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
When a property is changed, styles that are inside a @media selector are not being re-generated.
Expected Behavior 🤔
When a property is changed, all styles that are properties-dependent should be re-generated and re-applied to the component.
Steps to Reproduce 🕹
See example here: https://codesandbox.io/s/makestyles-mediaqueries-mygqi?file=/demo.js
Steps:
- “Swap color” button loads with background red and border/text-shadow blue
- Click on the “Swap color” button
- Background is changed to “blue” ✅
- Text-shadow is changed to “red” ✅
- Border is kept “blue” ❌
Context 🔦
I want to modify dynamically the fontSize of the input components (input, label, helper text) based on props.
I’m receiving a custom property called size that could be either Large or Small, and changing sizes of the components based on that property.
The fontSize is expected to be responsive too, so for example
size: Large =>
fontSizes
Sm: 14px
M: 16px
L: 20px
Xl: 24px
size: Small =>
fontSizes
Sm: 12px
M: 14px
L: 14px
Xl: 16px
I need to access the props at the rule level because I’m generating the @media selectors in another utility that I can’t modify
Your Environment 🌎
| Tech | Version |
|---|---|
| Material-UI | v4.9.9 |
| React | 16.13.1 |
| Browser | all |
| TypeScript | n/a |
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)

Top Related StackOverflow Question
An update, this issue is being resolved in v5 thanks to #22342 and the new
@material-ui/styled-enginepackage. The same codesandbox but updated & working with the latest alpha version: https://codesandbox.io/s/makestyles-mediaqueries-forked-h0iq5?file=/demo.js.An update, we have now made enough progress with the new
@material-ui/styled-enginepackage in v5 to move toward a progressive removal of the@material-ui/stylespackage (based on JSS). The current plan:sxprop +styled()API). We might for instance, invest in the documentation for using react-jss that has more or less the same API. We could also invest in an adapter to restore the previous API but with emotion, not JSS.withStyles/makeStylesAPI).This was made possible by the awesome work of @mnajdova.