By exporting and reusing styles in other components, you can consolidate your CSS logic into a single makeStyles
function, which can be stored in a centralized file for easy access.
export const useStyles = makeStyles(themes => ({
root: {
marginTop: '15px',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
flexGrow: '0'
},
menuButton: {
color: grey[800],
},
}));
There are several reasons why you might want to do this: for example, if you have a global theme that dictates using blue buttons but need to override with green for specific components while still maintaining inherited styles like fonts. This method allows for customization while staying consistent with the overall design.
This approach may be preferential, especially if your project follows a CSS in JS
style and you want to avoid mixing traditional CSS. By encapsulating styles within components, you can enforce a more structured approach to styling in your library.
Essentially, this method involves taking themes as input and applying modifiers to customize the theme for components utilizing the useStyles
class.
Furthermore, you can also apply these styles as a CSS class within your components for added flexibility.