reactjs - 样式化的组件算术运算
问题描述
我在这里有一个演示
它是一个简单的反应应用程序,我在其中使用带有主题的样式化组件
主题就像
import { DefaultTheme } from "styled-components";
export const theme: DefaultTheme = {
sizes: {
height: "50px",
width: "50px"
}
};
是否可以在样式组件中将主题值与算术运算一起使用
所以像
height: ${({ theme }) => theme.sizes.height}+
${({ theme }) => theme.sizes.height};
这在我的演示中不起作用,但我不知道语法是不正确还是不可能。
解决方案
要应用这个,你的主题应该是这样的,道具将是数字,而不是字符串。
export const theme: DefaultTheme = {
sizes: {
height: 50,
width: 50
}
};
所以你现在可以设置你的高度。
height: ${({ theme }) => theme.sizes.height + theme.sizes.height};
推荐阅读
- xpath - XPath 和 Priority 属性与 |
- javascript - 如何在反应中显示网络拓扑和状态?
- mysql - 计算多列的分组
- project-reactor - 如何创建仅在请求时才发出项目的发布者?
- c# - 带有 JSON 参数的 HttpClient 调用总是得到“值不能为空”
- matplotlib - 删除 x 轴上的空格,因为没有值
- java - JAVA 使用 IOUtils.toString 和 HttpEntity.getContent() 将 InputStream 转换为 null
- arrays - ES6 函数数组,这个有问题
- graph - 如何不截断图形 hbox 类别名称
- promise - 理解 ReasonML 中的 Js.Promise.resolve(.) 点语法