Задать вопрос
@GGatsby

Ошибка Invalid Hook Call Warning. В чем может быть проблема?

Использу Material-UI
Задача прокинуть пропс компонента в styles. Для этого использую makeStyles, createStyles.

на вы ходел получил ошибку


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);
  • Вопрос задан
  • 3487 просмотров
Подписаться 1 Средний Комментировать
Помогут разобраться в теме Все курсы
  • Нетология
    Frontend-разработка на React
    10 недель
    Далее
  • ProductStar
    Разработка на React
    6 недель
    Далее
  • Яндекс Практикум
    React-разработчик
    3 месяца
    Далее
Решения вопроса 1
rockon404
@rockon404 Куратор тега React
Frontend Developer
Вызов makeStyles возвращает хук. Хуки можно использовать только в теле функциональных компонентов.

По договоренности именования хук styles следует переименовать в useStyles.
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы
ITK academy Нижний Новгород
от 50 000 до 90 000 ₽
ITK academy Екатеринбург
от 50 000 до 90 000 ₽
от 250 000 до 300 000 ₽