Closed devpeerapong closed 5 years ago
@devpeerapong Please, don't use the two styling solutions at the same time (@material-ui/core/styles
and @material-ui/styles
). Don't miss this step: https://material-ui.com/css-in-js/basics/#migration-for-material-ui-core-users.
@oliviertassinari FWIW, I have the same issue as described above, and here is what I observe:
makeStyles
Hooks API, all works well. For instance, I can use theme
when using makeStyles
. When I log out the theme
to the console, I see that the custom fontFamily
for instance has properly been set.Typography
, though, I get the default font family, not my custom choicefontFamily
explicitly from theme for a class and apply it to the Typography
component, it worksAlso, I have the same problem when, for example, I do something <Typography color="primary">...
which uses the default primary color, not the primary color of my theme.
As soon as I wrap my full app with both the new ThemeProvider
as well as the old MuiThemeProvider
as OP above, it works.
And, as I said, storybook works consistently (thus, I guess my theme is fine).
I am including install
as above (even in its own file), I did remove pretty much everything from my component, it does not help. I am stumped.
Theme (typography part):
export const theme = createMuiTheme({
typography: {
useNextVariants: true,
fontFamily: "MyCustomFontThatWorksInStorybook",
htmlFontSize: 16,
}, ...
(also, using Typescript, and it all checks out)
"@material-ui/core": "^3.9.2", "@material-ui/styles": "^3.0.0-alpha.10" react/react-dom 16.8.3 (create-react-app based install)
Expected Behavior 🤔
withStyles(theme => {})
use theme that I provide from<ThemeProvider>
Current Behavior 😯
withStyles
use default themeSteps to Reproduce 🕹
Link: https://codesandbox.io/s/71vo9yxvp6
Simply change the App variable to
WithStylesThemeBeingOverrideByDefault
orCorrectTheme
to see the different.The top box is styled using
withStyles
The bottom box is styled usinguseTheme
to get the theme color and set thestyle
directlyContext 🔦
I am trying to style the background color with
withStyles
but the background color always be blue. but if IuseTheme()
to get thetheme.palette.primary.main
, It is the correct color. so In order to get thewithStyles
to use the correct theme color, I have to wrap theApp
withMuiThemeProvider
so It becomes like thisYour Environment 🌎