【问题标题】:I am getting (TypeError: Cannot read property 'down' of undefined)我得到了(TypeError:无法读取未定义的属性“向下”)
【发布时间】:2021-07-09 11:34:41
【问题描述】:

我有一个样式文件

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

export const useStyles = makeStyles((theme) => ({
  paperStyle: {
    width: 400,
    height: 320,
    display: "flex",
    justifyContent: "center",
    alignItems: "center",
    [theme.breakpoints.down("xs")]: {
      width:200
    },
  },
  animationStyle: {
    width: "90%",
    height: "90%",
  },
}));

我觉得一切都是正确的,我不明白为什么这会给我这个错误?我哪里错了? material-ui 的 Alpha 版本有什么变化吗?请帮忙。

这是CodeSandbox的链接

【问题讨论】:

  • 好吧,theme.breakpoints 是未定义的。你可以做一个 if 检查快速修复
  • theme.breakpoints没有问题,问题出在down。
  • 我删除了down('xs'),没有错误。
  • 使用 import { makeStyles } from "@material-ui/core/styles";

标签: reactjs material-ui


【解决方案1】:

也许可以尝试更换

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

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

【讨论】:

  • 这给了我Attempted import error: 'makeStyles' is not exported from '@material-ui/core/styles'. 错误
  • @Satyam 请你试试import { makeStyles } from "@material-ui/core;
  • Attempted import error: 'makeStyles' is not exported from '@material-ui/core'. 这是现在的错误
  • import { makeStyles } from "@material-ui/styles"; 这不会给出任何错误。当我删除那个有问题的部分时,它工作正常。
  • @AnuragParmar 谢谢!!问题在于版本material-ui/core@5.0.0beta 有导入问题。这就是为什么我得到错误!您可以在答案中指定版本吗?我会接受你的回答。再次感谢您!
猜你喜欢
  • 2021-11-13
  • 2021-04-13
  • 1970-01-01
  • 1970-01-01
  • 2016-09-22
  • 1970-01-01
  • 2020-11-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多