reactjs - 有没有办法在 Material UI 中扩展 makeStyle 类?
问题描述
我希望能够实现这样的目标:
const useStyles = makeStyles((theme) => ({
button: {
backgroundColor: 'red',
border: 'black solid 5px',
},
selectedButton: {
extend: 'button',
backgroundColor: 'yellow'
}
}))
所以类'selectedButton'仍然会有黑色边框,但背景颜色会改变。
解决方案
使用makeStyles
const button = {
backgroundColor: "red",
border: "black solid 5px",
};
const useStyles = makeStyles({
button,
selectedButton: {
...button,
backgroundColor: "yellow"
}
});
使用withStyles
const StyledButton = withStyles({
root: {
backgroundColor: "red",
border: "black solid 5px"
}
})(Button);
const SelectedButton = withStyles({
root: {
backgroundColor: "yellow"
}
})(StyledButton);
推荐阅读
- c# - 无法在 C# 中使用集合初始化程序错误初始化十进制类型
- javascript - 如何查找数组是否有其他元素?
- sendgrid - 如何在 sendgrid node.js v3 客户端中将 pdf 文件作为附件发送
- javascript - Number.parseInt() 不断返回 NaN
- excel - Excel VBA:如何根据具有附加条件的数据范围将行从一个工作表复制到另一个工作表以缩小结果范围?
- javascript - 查询字符串更改时重新渲染 React 组件
- c - 从 MMA7455L 传感器 i2c 获取数据
- node.js - 如何正确使用带有 npm 脚本的 parallelshell?
- java - 如何验证具有不同架构的 Avro 格式数据
- android - 带有错误代码 3 的乱舞横幅