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.

[Theming] Apply styles to multiple Components

See original GitHub issue

In 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:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
michaldudakcommented, Sep 15, 2021

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

components: {
  MuiListItemButton: MuiListItemButton,
  MuiMenuItem: {
    defaultProps: {
      component: LinkBehavior,
    },
  },
}

and, if MuiListItemButton is not defined in this scope, the runtime rightfully complains.

0reactions
michaldudakcommented, Sep 15, 2021

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.

Read more comments on GitHub >

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

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