[Theming] Apply styles to multiple Components
See original GitHub issueIn my theme.js
file where I define my global Mui styles, I would like to be able to do something like the following in order to reduce code repetition and make my files shorter:
--- SNIP ---
components: {
MuiListItemButton, MuiMenuItem: {
defaultProps: {
component: LinkBehavior,
},
},
}
--- SNIP ---
When I try the above, I get the following error message:
ReferenceError: MuiListItemButton is not defined
Why is it not possible in this object to state more than one key?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Grouping Multiple CSS Selectors in One Style Property
When you group CSS selectors, you apply the same styles to several different elements without repeating the styles in your stylesheet.
Read more >css - Nested themable components: apply styles depending ...
Simply apply the theme HTML class to each themable component explicitly. This is what I'm doing, but I don't see it a solution....
Read more >Theming and Theme Switching with React and styled ...
Create and save multiple themes; Select and apply a theme ... styled-components: A flexible way to style React components with CSS.
Read more >Working with multiple CSS themes. CodeShare - Medium
In the first article of this series we saw how variables work on CSS and how we can use them to create themes...
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 ...
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
What you’re proposing is a shorthand property initializer introduced in ES2015 (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#new_notations_in_ecmascript_2015).
It translates to
and, if
MuiListItemButton
is not defined in this scope, the runtime rightfully complains.Shorthand property initializer is a feature of ECMAScript, so you can use it in projects with MUI. It just does not work (by design) the way you would like.