G
G
GGatsby2019-07-02 14:13:02
typescript
GGatsby, 2019-07-02 14:13:02

Invalid Hook Call Warning error. What could be the problem?

I use Material-UI
The task is to throw the props of the component into styles. For this I use makeStyles, createStyles.
you got an error


Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.

const styles = makeStyles((theme: Theme) => {
  return {
    root: {
      flexGrow: 1,
      height: "100%",
    },
    appFrame: {
      display: "flex",
      flexDirection: "column",
      overflow: "auto",
      position: "relative",
      width: "100%",
      height: "100%",
      minHeight: "100%",
      zIndex: 1,
    },
    hide: {
      display: "none",
    },
    drawerPaper: {
      width: (props: any) => props.width,
    },
    drawerHeader: {
      alignItems: "center",
      display: "flex",
      justifyContent: "center",
      padding: "0 0px",
      ...theme.mixins.toolbar,
      minHeight: "48px !important",
    },
    content: {
      backgroundColor: theme.palette.background.default,
      flexGrow: 1,
      marginTop: theme.spacing(8),
      padding: theme.spacing(3),
      transition: theme.transitions.create("margin", {
        duration: theme.transitions.duration.leavingScreen,
        easing: theme.transitions.easing.sharp,
      }),
    },
    "content-left": {
      marginLeft: 0,
    },
    contentShift: {
      transition: theme.transitions.create("margin", {
        duration: theme.transitions.duration.enteringScreen,
        easing: theme.transitions.easing.easeOut,
      }),
    },
    "contentShift-left": {
      marginLeft: drawerWidth,
    },
    footer: {
      color: theme.palette.primary.contrastText,
      background: theme.palette.primary.main,
      padding: theme.spacing(1.5),
      textAlign: "center",
    },
    footerLink: {
      color: theme.palette.primary.contrastText,
      fontWeight: "bolder",
      "&:hover": {
        color: theme.palette.primary.contrastText,
      },
    },
  };
}) as any;

В компоненте обьявляю const classes = styles(props);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-07-02
@GGatsby

The call to makeStyles returns a hook. Hooks can only be used in the body of functional components.
By convention, the styles hook should be renamed to useStyles.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question