React--createElement_js+css

编译过程jsx->js

  • 编译前
const el = (
    <div id='box'>
        child1
         <p style={{ color: 'red' }} >child2</p>
         <span>child3</span>
    </div>
)
  • 编译后
var el = React.createElement("div", {
    id: "box"
  }, "child1 ", React.createElement("p", {
    style: {
      color: 'red'
    }
  }, "child2"), React.createElement("span", null, "child3"));

底层实现

function createElement(tag, props = {}, ...children) {
    return {
        tag,
        props,
        children
    }
}
export default createElement;