I'm using Material UI in my project and at same time, we have a component library (a npm package with many shared React components).
These components in the library are also based on Material UI.
So when I import these components from library to use in my project, it's duplicating the <styles> block to some component that're in use (for example MuiButtonBase-root).
Based on this, it's reseting some css styles, when the second MuiButtonBase-root come after.
Is there a solution for this?
Edit 1:
Here's an example, maybe components are not in this order, because I'm not really sure in which order the issue happen.
// myProject
import { AppBar, Tabs, Tab, ThemeProvider } from '@material-ui/core';
import { Button, SharedComponentProvider } from '@shared-components'; // components based on MUI
function App() {
return (
<SharedComponentProvider>
<ThemeProvider theme={fooTheme}>
<AppBar position="static">
<Tabs>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
</Tabs>
</AppBar>
<Button>Click me</Button>
</ThemeProvider>
</SharedComponentProvider>
);
}
The SharedComponentProvider is like this:
import { StylesProvider, createGenerateClassName } from '@material-ui/core/styles';
const generateClassName = createGenerateClassName({
seed: 'shared-components',
});
function SharedComponentProvider({ children }: any) {
return (
<ThemeProvider theme={sharedTheme}>
{ children }
</ThemeProvider>
);
}
Since Tab component is also based on MUI Button component, so it will create two tags of <style> with . MuiButtonBase-root inside, which can end up in this case.