简体   繁体   English

MUI 断点无法识别“theme.breakpoints.down”

[英]MUI breakpoints not recognizing "theme.breakpoints.down"

Goal: Hide navMenu when breakpoint is tablet and under, so I can replace with a hamburger menu目标:当断点位于平板电脑及下方时隐藏导航菜单,以便我可以用汉堡包菜单替换

In terminal in VS code, it says compiled successfully, but in the browser I see:在 VS 代码的终端中,它说编译成功,但在浏览器中我看到:

TypeError: Cannot read properties of undefined (reading 'down')类型错误:无法读取未定义的属性(读取“向下”)

I tried instructions here: StackOverflow Question , with no luck.我在这里尝试了说明: StackOverflow Question ,但没有运气。

Can someone point me in the right direction?有人可以指出我正确的方向吗?

import AppBar from "@mui/material/AppBar";
import Box from "@mui/material/Box";
import Toolbar from "@mui/material/Toolbar";
import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";
import { makeStyles } from "@mui/styles";

const useStyles = makeStyles((theme) => ({
  navMenu: {
    [theme.breakpoints.down('md')]: {
      display: "none",
    },
  },
}));

const Navbar = () => {
  const classes = useStyles();

  return (
    <Box sx={{ flexGrow: 1 }}>
      <AppBar position="static" style={{ backgroundColor: "#061B2E" }}>
        <Toolbar>
          <Typography variant="h6" component="div" sx={{ flexGrow: 1 }}>
            Name
          </Typography>
          <Box className={classes.navMenu}>
            <Button color="inherit">Item 1</Button>
            <Button color="inherit">Item 2</Button>
            <Button color="inherit">Item 3</Button>
            <Button color="inherit">Item 4</Button>
          </Box>
        </Toolbar>
      </AppBar>
    </Box>
  );
};

export default Navbar;

Great question, which version of MUI are you using?好问题,您使用的是哪个版本的 MUI? They're kind of shifting away from makeSyles in favor of styled components, but this method is still supported (we still use it exclusively on my team).他们有点从makeSyles转向支持样式化组件,但仍然支持这种方法(我们仍然只在我的团队中使用它)。 You may need to change your import statement to import { makeStyles } from '@material-ui/core';您可能需要将导入语句更改为import { makeStyles } from '@material-ui/core';

这是有关断点的文档,因为您似乎正在使用 material-ui v5(现在称为 mui) https://mui.com/customization/breakpoints/#main-content

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM