forked from mx-bernhard/tss-react-performance-issue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButton.tsx
50 lines (44 loc) · 1.17 KB
/
Button.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import Button from "@mui/material/Button";
import { range } from "lodash-es";
import { PropsWithChildren } from "react";
import { tss } from "tss-react/mui";
type Props = {
className?: string;
};
export function MyButton(props: PropsWithChildren<Props>) {
const { className } = props;
const { classes, cx } = useStyles();
return (
<Button className={cx(classes.root, className)}>{props.children}</Button>
);
}
// change this to false to observe the big performance difference
const slowDown = true;
const useStyles = tss.create(({ theme }) => ({
...Object.fromEntries(
range(1, slowDown ? 1000 : 1).map((i) => [
"some-class-" + i,
{
color: "red",
"&:hover": {
border: "4px solid black",
},
[theme.breakpoints.up("md")]: {
border: "10px solid cyan",
},
},
])
),
root: {
minWidth: "80px",
color: "red",
// When the curser is over the button has a black border
"&:hover": {
border: "4px solid black",
},
// On screens bigger than MD the button will have a big cyan border
[theme.breakpoints.up("md")]: {
border: "10px solid cyan",
},
},
}));