reactjs - TypeError:无法读取材料 ui 中未定义的属性(读取“断点”)
问题描述
我正在尝试在 Material UI (React Project) 中使用断点。我正在使用 Material UI v5.0.1
const useStyles = makeStyles((theme) => ({
gridRight: {
width: "50%",
height: "350px",
backgroundColor: "black",
opacity: 0.3,
borderRadius: 20,
padding: 10,
color: "white",
[theme.breakpoints.down("md")]: {
width: "100%",
},
},
}));
但我得到了错误:
TypeError: Cannot read properties of undefined (reading 'breakpoints')
我也尝试过使用,ThemeProvider
但错误仍然存在。另外,我检查了 Material Ui 文档中的默认用法,错误仍然是未定义的断点。
完整代码
import "./welcome.css";
import * as React from "react";
import { Typography, Grid } from "@mui/material";
import { makeStyles } from "@mui/styles";
const useStyles = makeStyles((theme) => ({
gridRight: {
width: "50%",
height: "350px",
backgroundColor: "black",
opacity: 0.3,
borderRadius: 20,
padding: 10,
color: "white",
[theme.breakpoints.down("md")]: {
width: "100%",
},
},
}));
const Welcome = () => {
const PF = process.env.REACT_APP_PUBLIC_FOLDER;
const classes = useStyles();
return (
<div
style={{
backgroundImage: `URL(${PF + "back.jpg"})`,
backgroundRepeat: "no-repeat",
backgroundPosition: "center",
backgroundSize: "cover",
height: "calc(100vh)",
}}
>
<Grid container rowSpacing={1} columnSpacing={{ xs: 1, sm: 2, md: 3 }}>
<Grid item xs={12} md={6}>
<div className={classes.gridLeft}>
<Typography>Side One </Typography>
</div>
</Grid>
<Grid item xs={12} md={6}>
<div className={classes.gridRight}>
<Typography>Side Two </Typography>
</div>
</Grid>
</Grid>
</div>
);
};
export default Welcome;
解决方案
推荐阅读
- c# - 将 C# DLL 注入另一个应用程序并显示它
- ruby-on-rails - Rails/Ruby - 使用语言环境将字符串格式化为日期
- angular - Angular点击事件问题错误发现?
- c - 大于 UINT32 的数字的 sprintf 格式说明符
- java - 尝试运行其实现的某些内容时未使用扫描仪
- c# - .net core 2.2 无法处理正文中的加密字符串,即使 mediatype 说 application/json
- php - FPDF 生成单个页面而不是一个大页面
- php - Nginx 重写目录并排除子目录
- node.js - 我应该使用 cookie 还是本地存储将数据持久化到前端?
- html - 如何保持文本与其父 div 的宽度相同?