我有下面的MUI4代码迁移到MUI5。
在MUI4下,我有:
import { createStyles, makeStyles } from '@material-ui/core';
import { Theme } from '@material-ui/core/styles/createMuiTheme';
type Props = {
darkMode?: boolean;
};
const useStyles = makeStyles<Theme, Props>((theme: Theme) =>
createStyles({
button: (props: Props) => ({
color: props.darkMode ? '#fff' : '#AE4',
}),
}),
);
export default useStyles;
重写MUI5:
import { makeStyles } from 'tss-react/mui'
import { Theme } from '@mui/material/styles'
type Props = {
darkMode?: boolean;
};
const useStyles = makeStyles<Theme, Props>((theme: Theme) => ({
return {
button: (props: Props) => ({
color: props.darkMode ? '#fff' : '#AE4',
}),
}
})
我遇到了错误
Type 'Props' does not satisfy the constraint 'string'.ts(2344)
正确的做法是什么?
1条答案
按热度按时间unguejic1#
在docs中很好地定义了如何实现这一点: