After experimenting with React and Material-UI, I came across an interesting pattern in the code. When using the useStyle
function, developers often create a class called 'root' and utilize the tag & > *
. I tried to research the meaning behind this but couldn't find clear answers.
For reference, you can view an example from the official documentation here:
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Paper from '@material-ui/core/Paper';
const useStyles = makeStyles(theme => ({
root: {
display: 'flex',
flexWrap: 'wrap',
'& > *': {
margin: theme.spacing(1),
width: theme.spacing(16),
height: theme.spacing(16),
},
},
}));
export default function SimplePaper() {
const classes = useStyles();
return (
<div className={classes.root}>
<Paper />
</div>
);
}