Material ui 材料用户界面和类型脚本

Material ui 材料用户界面和类型脚本,material-ui,Material Ui,我不熟悉TypeScript,并尝试遵循material ui repository中提供的示例。提供的示例代码是传递rootCSS类。我想再传递几个CSS类和'root' const styles: StyleRulesCallback<'root'> = theme => ({ root: { textAlign: 'center', paddingTop: theme.spacing.unit * 20, } }); const styles:S

我不熟悉TypeScript,并尝试遵循material ui repository中提供的示例。提供的示例代码是传递
root
CSS类。我想再传递几个CSS类和'root'

const styles: StyleRulesCallback<'root'> = theme => ({
  root: {
    textAlign: 'center',
    paddingTop: theme.spacing.unit * 20,
  }
});
const styles:StyleRulesCallback=theme=>({
根目录:{
textAlign:'中心',
paddingTop:theme.space.unit*20,
}
});
下面是material ui提供的完整示例代码的链接


您可以这样实现:

const styles: StyleRulesCallback = theme => ({
    paper: {
        maxWidth: 1000,
        minWidth: 1000,
        display: 'inline-block'
    },
    table: {
        maxWidth: 1000,
    },
});
并在组件中使用类,如下所示:

 <Paper className={classes.paper}>

请查看此样板作为参考:

您可以这样实现:

const styles: StyleRulesCallback = theme => ({
    paper: {
        maxWidth: 1000,
        minWidth: 1000,
        display: 'inline-block'
    },
    table: {
        maxWidth: 1000,
    },
});
并在组件中使用类,如下所示:

 <Paper className={classes.paper}>

请查看此样板作为参考:
Toni给出的内容在
4.1.1
中似乎不再有效(我正在使用的)。相反,您需要以下内容

import { StyleRulesCallback, Theme } from '@material-ui/core/styles';

interface IComponentProps {
  // props
}

const styles: StyleRulesCallback<Theme, IComponentProps> = theme = ({
  someClass: {}
  someClassWithProps: (props) => ({})
})

Toni给出的内容在
4.1.1
(我正在使用的)中似乎不再有效。相反,您需要以下内容

import { StyleRulesCallback, Theme } from '@material-ui/core/styles';

interface IComponentProps {
  // props
}

const styles: StyleRulesCallback<Theme, IComponentProps> = theme = ({
  someClass: {}
  someClassWithProps: (props) => ({})
})