react中jsx文件是如何转换成js对象的

通过在线babel转换器,转换出jsx是如何变成js对象的

jsx文件

加入了正常的标签以及嵌套标签以及方法属性

function hello() {
  click=()=>{
    console.log("hello")
  }
  return <div>
          <button onclick={this.click.bind(this)}>
            helloWorld
          </button>
          </div>;
}

通过babel转换之后

"use strict";

function hello() {
  click = function click() {
    console.log("hello");
  };

  return React.createElement("div", null, React.createElement("button", {
    onclick: this.click.bind(this)
  }, "helloWorld"));
}

在线babel编辑器 测试

原文地址:https://www.cnblogs.com/lidedong/p/10413419.html