[Docs] No mention of having to wrap the components with ThemeProvider
See original GitHub issueI upgraded my project from Material UI V3 to V4 (Beta).
After the upgrade I changed my withStyles imports from:
import withStyles from '@material-ui/core/styles/withStyles';
to
import withStyles from '@material-ui/styles/withStyles';
Now I get the error message:
index.js:1446 Warning: Material-UI: the `styles` argument provided is invalid.
You are providing a function without a theme in the context.
One of the parent elements needs to use a ThemeProvider.
Do you always have to use a ThemeProvider as of Material-UI 4? If yes, I think this should be mentioned in the docs somewhere. Before I think the was a default value supplied. At least my styles would work without having a ThemeProvider.
Issue Analytics
- State:
- Created 4 years ago
- Comments:19 (14 by maintainers)
Top Results From Across the Web
[Docs] No mention of having to wrap the components ... - GitHub
I upgraded my project from Material UI V3 to V4 (Beta). After the upgrade I changed my withStyles imports from: import withStyles from ......
Read more >Advanced Usage - styled-components
Theming. styled-components has full theming support by exporting a <ThemeProvider> wrapper component. This component provides a theme to all React components ...
Read more >How can I use useTheme in Material UI 5? - Stack Overflow
SO question labelled "access the theme from outside material-ui component" which references the legacy docs ( @material-ui/styles does not exist ...
Read more >Theming - Material UI - MUI
Theming. Customize MUI with your theme. You can change the colors, the typography and much more. The theme specifies the color of the...
Read more >How to use Themes in styled-components - DEV Community
Like I mentioned before, the theme provider takes a theme prop. In that prop is where we reference the object we create above....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’m on vacation so I don’t have computer access, but the makeStyles function takes an object with options. One of the options is defaultTheme, which I assign the same theme that the ThemeProvider gets (imported from some module)
I hope this makes sense
On Thu, 1 Aug 2019, 12:42 Harley Alexander, notifications@github.com wrote:
For
import withStyles from '@material-ui/styles/withStyles';, yes. Forimport withStyles from '@material-ui/core/styles/withStyles';, no.It’s the first segment in https://next.material-ui.com/css-in-js/advanced/. Maybe we can emphasize more that the two imports use different defaults but I doubt it will help much.
PS: Prefer
import { withStyles } from '@material-ui/core/styles';. The path import has limited tree-shaking support.