1

I'm using makeStyles from Material-UI in ReactJS to style components but classes are injected first in header and doesn't overwrite the component classes.

This is the head styles screenshot: a busy cat

As you can see, makeStyles did the "OAuth" classes, but are being injected first and not later making impossible to overwrite the components classes.

this is my style (makeStyles) code:

import { makeStyles } from '@material-ui/styles';

const useStyles = makeStyles(
  theme => ({
    container: {
      alignItems: 'start',
      [theme.breakpoints.down('xs')]: {
        display: 'block',
        margin: 0,
        padding: 0
      }
    },
    paper: {
      width: '100%',
      maxWidth: '600px',
      margin: '.5rem',
      marginTop: '15vh',
      [theme.breakpoints.down('xs')]: {
        margin: 0,
        height: '100%',
        maxHeight: '100%'
      }
    }
  }),
  { name: 'OAuth' }
);

export default useStyles;

And this is how I'm trying to overwrite classes:

import React from 'react';
import useStyles from './styles';
import Dialog from '@material-ui/core/Dialog';
import Box from '@material-ui/core/Box';

const OAuth = () => {
  const classes = useStyles();
  const oauthClasses = {
    container: classes.container,
    paper: classes.paper
  };

  return (
    <Dialog open={true} classes={oauthClasses}>
      <Box>
        Dialog content
      </Box>
    </Dialog>
  );
};

export default OAuth;

So, how could I make my classes to be injected at the end to overwrite the main classes of the components?

Phoxer
  • 413
  • 1
  • 4
  • 15
  • 1
    The issue is with the order of your imports. Import the `useStyles` function after importing all of the Material-UI components. See my other answer (in the "duplicate" flag comment) for more details. – Ryan Cogswell Aug 27 '19 at 18:57

0 Answers0