尝试通过react组件内的变量设置字体颜色,但我的<span>
给出了错误:
Type '{ style: "color:yellow"; }' is not assignable to type 'HTMLProps<HTMLSpanElement>'
黄色只是用于测试,我最后会用{color}替换。
import * as React from 'react';
export interface SkillListItemProps {
name: string
color: string
// Icons:
}
interface SkillListItemState{
}
export class SkillListItem extends React.Component<SkillListItemProps,SkillListItemState>{
public render(): JSX.Element{
const {name, color} = this.props;
return (
<div className="SkillListItem">
<span style="color:yellow">{name}</span>
</div>
)
}
}
答案 0 :(得分:1)
你必须使用一个对象,如下所示:
<span style={{color: "yellow"}}>{name}</span>
JSFiddle演示:https://jsfiddle.net/4wcmcpv3/1/