Material-UI utilizes a unique class name generator to create distinct class names for styled components in order to achieve style isolation. The prefix of the class name varies depending on the current environment.
- During non-production mode, the component's displayed name is used as the class name prefix
- In production mode, the default prefix
jss
is utilized
To observe the change in class name prefix, you can simulate different environments by adjusting process.env.NODE_ENV
at the start of your program.
// Set to "production" to view the difference in class name prefix
process.env.NODE_ENV = "development";
class App extends React.Component {
static displayName = "MyAmazingApp";
render() {
const { classes } = this.props;
return <div className={classes.root}>Hello world</div>;
}
}
const styles = {
root: {
backgroundColor: "grey"
}
};
const AppWithRouter = withRouter(App);
const MyApp = withStyles(styles)(AppWithRouter);
console.log(AppWithRouter.displayName); // withRouter(MyAmazingApp)-root-1
Generated class name for the element in development:
withRouter(MyAmazingApp)-root-1
In a production environment:
jss1
Interactive Demo
Check out the live demo here!