createGenerateClassName in Material UI v5
See original GitHub issueDuplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior 😯
What’s the proper alternative to legacy https://mui.com/styles/api/#creategenerateclassname-options-class-name-generator if @mui/styles package is not used, and all styles are created via MUI System (sx)?
By default all classes (even on production) are prefixed with Mui
and css
which may become a problem if multiple MUI apps are on the same page (Module Federation especially):
Expected behavior 🤔
Documentation is only available for legacy implementation, I’ve scanned the whole site, including migration instructions, and found no docs related to how to do it properly.
Steps to reproduce 🕹
Steps:
- Open https://codesandbox.io/s/material-ui-issue-latest-s2dsx
- Check the devtools:
<p class="MuiTypography-root MuiTypography-body1 css-ahj2mt-MuiTypography-root">MUI example. Please put the code to reproduce the issue in src/Demo.js</p>
Context 🔦
I need to have 2 (or more) Material-UI based apps (potentially with different versions) on the same page w/o clashing styles.
Your environment 🌎
`npx @mui/envinfo`
@emotion/react latest (11.7.0)
@emotion/styled latest (11.6.0)
@mui/material latest (5.2.2)
react latest (17.0.2)
react-dom latest (17.0.2)
Issue Analytics
- State:
- Created 2 years ago
- Comments:17 (9 by maintainers)
Top Results From Across the Web
createGenerateClassName in Material UI v5 - Stack Overflow
Show activity on this post. Have a look at https://mui.com/guides/classname-generator/, it is the replacement of createGenerateClassName .
Read more >createGenerateClassName in Material UI v5 #30011 - GitHub
I need to have 2 (or more) Material-UI based apps (potentially with different versions) on the same page w/o clashing styles. Your environment ......
Read more >Styles API - MUI System
StrictMode or React 18. createGenerateClassName([options]) => class name generator. A function which returns a class name ...
Read more >ClassName generator - Material UI - MUI
Configure classname generation at build time. This API is introduced in @mui/material (v5.0.5) as a replacement of deprecated createGenerateClassName .
Read more >ClassName Generator - MUI
Configure classname generation at build time. This API is introduced in @mui/material (v5.0.5) as a replacement of deprecated createGenerateClassName .
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 FreeTop 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
Top GitHub Comments
The issue is fixed, you have to change the import:
https://mui.com/guides/classname-generator/#main-content
I’ve also found out that there’s an alternative way:
Is this legit? Which one is better, this one or via
ClassNameGenerator.configure
?