小编Yon*_*man的帖子

使用 typescript 将自定义断点添加到 Material ui

我知道在createMuiTheme()函数中您可以像这样更新断点的值。

const theme = createMuiTheme({
  breakpoints: {
    values: {
      xs: 0,
      sm: 600,
      md: 960,
      lg: 1280,
      xl: 1920,
    },
  },
})
Run Code Online (Sandbox Code Playgroud)

我还知道 Material UI(相对)最近更改了它,您可以为断点添加自定义值。

  breakpoints: {
    values: {
      tablet: 640,
      laptop: 1024,
      desktop: 1280,
    },
  },
});
Run Code Online (Sandbox Code Playgroud)

但是,我使用的是 Typescript,无法通过覆盖断点值来使其工作,如下所示:

declare module "@material-ui/core/styles/createBreakpoints"
{
  interface BreakpointOverrides
  {
    xs: false; // removes the `xs` breakpoint
    sm: false;
    md: false;
    lg: false;
    xl: false;
    tablet: true; // adds the `tablet` breakpoint
    laptop: true;
    desktop: true;
  }
}
Run Code Online (Sandbox Code Playgroud)

而是得到这个错误 Type '{ …

typescript reactjs material-ui

5
推荐指数
1
解决办法
5654
查看次数

标签 统计

material-ui ×1

reactjs ×1

typescript ×1