【发布时间】:2021-03-27 00:41:37
【问题描述】:
我在我的学习项目中使用 material-ui 和 typescript。我遇到了一个我不知道如何解决的问题。
我在 material-ui 主题中使用自定义断点。
import { createMuiTheme } from '@material-ui/core/styles';
const theme = createMuiTheme({
breakpoints: {
values: {
small: 480,
mobile: 640,
tablet: 960,
laptop: 1280,
desktop: 1440,
},
},
});
export { theme };
并创建新文件 BreakpointsOptions.d.ts
import * as React from 'react';
import { BreakpointOverrides } from '@material-ui/core/styles/createBreakpoints';
declare module '@material-ui/core/styles/createBreakpoints' {
interface BreakpointOverrides {
/* ------------------------------------- */
/* Removes defaults breakpoint */
/* ------------------------------------- */
xs: false;
sm: false;
md: false;
lg: false;
xl: false;
/* ------------------------------------- */
/* Adds new breakpoint */
/* ------------------------------------- */
small: true;
mobile: true;
tablet: true;
laptop: true;
desktop: true;
}
}
现在我想使用 Material-ui 中的 Container。
import React, { FC } from 'react';
import Container from '@material-ui/core/Container';
type PropTypes = {
component: string;
children: NonNullable<React.ReactNode>;
className?: string;
};
export const MaxWidthContainer: FC<PropTypes> = (props: PropTypes) => {
const { component, children, className } = props;
return (
<Container component={component} maxWidth="desktop" className={className}>
{children}
</Container>
);
};
但我得到了错误 enter image description here
那么,如何在不修改“node_modules”文件夹中的文件的情况下修复此错误?
【问题讨论】:
标签: reactjs typescript material-ui