javascript - 将字体样式从对象映射映射到 map() 的正确语法
问题描述
React、JS 和 Material UI
好的,可能是一个菜鸟问题,但是我在我的地图函数的样式属性中的语法到底做错了什么?
字体.jsx
export const fonts = [
{
fontName: 'Abril',
key: 'abril',
fontFamily: "'Abril Fatface', cursive;",
},
{
fontName: 'Bangers',
key: 'bangers',
fontFamily: "'Bangers', cursive;",
},
{
fontName: 'Bebas',
key: 'bebas',
fontFamily: "'Bebas Neue', cursive;",
},
{
fontName: 'Bungee',
key: 'bungee',
fontFamily: "'Bungee', cursive;",
},
{
fontName: 'Dancing',
key: 'dancing',
fontFamily: "'Dancing Script', cursive;",
},
{
fontName: 'Fascinate',
key: 'fascinate',
fontFamily: "'Fascinate', cursive;",
},
{
fontName: 'Frijole',
key: 'frijole',
fontFamily: "'Frijole', cursive;",
},
{
fontName: 'Girassol',
key: 'girassol',
fontFamily: "'Girassol', cursive;",
},
{
fontName: 'Goblin',
key: 'goblin',
fontFamily: "'Goblin One', cursive;",
},
{
fontName: 'Graduate',
key: 'graduate',
fontFamily: "'Graduate', cursive;",
},
{
fontName: 'Great Vibes',
key: 'greatVibes',
fontFamily: "'Great Vibes', cursive;",
},
{
fontName: 'Shadows',
key: 'shadows',
fontFamily: "'Shadows Into Light', cursive;",
},
{
fontName: 'Krona',
key: 'Krona',
fontFamily: "'Krona One', sans-serif;",
},
{
fontName: 'Lobster',
key: 'Lobster',
fontFamily: "'Lobster', cursive;",
},
{
fontName: 'Newsreader',
key: 'newsreader',
fontFamily: "'Newsreader', serif;",
},
{
fontName: 'Permanent Marker',
key: 'permanentMarker',
fontFamily: "'Permanent Marker', cursive;",
},
{
fontName: 'Righteous',
key: 'righteous',
fontFamily: "'Righteous', cursive;",
},
{ fontName: 'Spartan', key: 'spartan', fontFamily: "'Spartan', sans-serif;" },
];
和我的 map() 函数:
<Select label="Font" onChange={handleFont} defaultValue="Abril" className={classes.selectEmpty} value={font}>
{fonts.map((el, i) => (
<MenuItem key={el.key} value={el.fontName} style={{ fontFamily: el.fontFamily }}>
{el.fontName}
</MenuItem>))}
</Select>
我得到的错误是:警告:样式属性值不应包含分号。改用“fontFamily: 'Spartan', sans-serif”。
我想我知道我需要做什么,但不知道如何去做。对于已经在这方面花费太多时间的苦苦挣扎的菜鸟有什么帮助吗?
解决方案
iz_ 在评论中帮助回答了我的愚蠢问题。谢谢芽。
删除 ; 从我的物品中成功了
推荐阅读
- android - TextView 中的白屏
- rust - 使用 Diesel 的 `belongs_to` 属性时“使用未声明的类型或模块”
- python - run.font.italic 和 run.font.bold 返回 None 而不是 True
- java - Java:如何不仅按名称,而且按大小和内容搜索文件夹中的重复文件?
- c++ - 如何自动创建字符串的编译时容器
- git - Azure DevOps - 我应该将代码从源合并到我的分支并提交吗?
- vue.js - 构建生产后,Vue路由器无法正常工作
- flutter - 我使用堆栈封装的 3 个容器来获得类似这样的布局,现在我想让页面滚动?
- html - 如何将 2 个 div 彼此相邻放置
- python - 合并和组合 2 列不同的数据框