如果以这种方式创建,如何向 React Element 添加样式?
How to add style to React Element if it's created this way?
var MyElement = React.createClass({displayName: "FormatParagraph",
render: function () {
return (
React.createElement("p", null, this.props.paragraph)
);
}
});
如何向其中添加样式对象?
createElement
的第二个参数是属性的散列,其中键是属性名称,值是属性值。 style
属性将样式名称散列为值。所以,例如:
React.createElement("p", {style: {color: "red", backgroundColor: "blue"}}, this.props.paragraph)
React.createElement("p", {id : 'div1', className : 'news'}, this.props.paragraph)
这样您就可以在 id/class
.
中使用 App.css
中指定的 CSS
var MyElement = React.createClass({displayName: "FormatParagraph",
render: function () {
return (
React.createElement("p", null, this.props.paragraph)
);
}
});
如何向其中添加样式对象?
createElement
的第二个参数是属性的散列,其中键是属性名称,值是属性值。 style
属性将样式名称散列为值。所以,例如:
React.createElement("p", {style: {color: "red", backgroundColor: "blue"}}, this.props.paragraph)
React.createElement("p", {id : 'div1', className : 'news'}, this.props.paragraph)
这样您就可以在 id/class
.
App.css
中指定的 CSS