如果以这种方式创建,如何为React Element添加样式?

Pyt*_*eat 17 reactjs

var MyElement = React.createClass({displayName: "FormatParagraph",
    render: function () {
        return (
            React.createElement("p", null, this.props.paragraph)
            );
    }
});
Run Code Online (Sandbox Code Playgroud)

如何为此添加样式对象?

Mic*_*ley 26

第二个参数createElement是属性的散列,其中键是属性名称,值是属性值.该style属性将样式名称的哈希值赋予值.所以,例如:

React.createElement("p", {style: {color: "red", backgroundColor: "blue"}}, this.props.paragraph)
Run Code Online (Sandbox Code Playgroud)