使用 WithStyles 来扩充你的属性

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//不推荐
const styles = (theme: Theme) => createStyles({
  root: { /* ... */ },
  paper: { /* ... */ },
  button: { /* ... */ },
});
 
interface Props {
  // 未被注入样式的属性
  foo: number;
  bar: boolean;
  // 被注入样式的属性
  classes: {
    root: string;
    paper: string;
    button: string;
  };
}
 
//推荐:
import { WithStyles, createStyles } from '@material-ui/core';
 
const styles = (theme: Theme) => createStyles({
  root: { /* ... */ },
  paper: { /* ... */ },
  button: { /* ... */ },
});
 
interface Props extends WithStyles<typeof styles> {
  foo: number;
  bar: boolean;
}

Leave a Reply

Your email address will not be published. Required fields are marked *