question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Docs] No mention of having to wrap the components with ThemeProvider

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:19 (14 by maintainers)

github_iconTop GitHub Comments

3reactions
Zachecommented, Aug 2, 2019

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:

@Zache https://github.com/Zache can you please provide an example?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mui-org/material-ui/issues/15528?email_source=notifications&email_token=AA3AXQBWIDFEKW7TPH35443QCK4ZDA5CNFSM4HJJFZFKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3KEZTQ#issuecomment-517229774, or mute the thread https://github.com/notifications/unsubscribe-auth/AA3AXQBQGXF6ABQ52VDAPHTQCK4ZDANCNFSM4HJJFZFA .

3reactions
eps1loncommented, Apr 30, 2019

Do you always have to use a ThemeProvider as of Material-UI 4?

For import withStyles from '@material-ui/styles/withStyles';, yes. For import 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found