React渲染

JSX如何生成element

    return(
<div className="box">
<div> header </div>
hello world
</div>
)

他会经过babel编译成React.createElement的表达式

return(
React.createElement(
'div',
{className:'box'},
React.createElement(
'div',
null,
'header'
),
'hello world'
)
)

createElement()是用来组成虚拟DOM树

createElement的三个参数

  1. type -> 标签

  2. attributes => 属性标签,没有的话,可以为null

  3. children => 标签的子节点

最后的element对象的值

{
type:'div',
props:{
className:'box',
children:[
{
type: "div",
props:{
children:"header"
}
},
"Hello world"
]
}
}

element如何生成真实节点

而其中的ReactDOMComponent等等,属于React的私有类,React自己使用 ,不会暴露给用户的

常用的有:mountComponent,updateConponent等,而我们自定义的生命周期函数以及render函数都是在私有类的方法里被调用

ReactDOMComponent 作用

ReactDOMComponent的mountComponent方法,这个方法的作用是:将element转成真实DOM节点,并且插入到相应的container里,然后返回markup(realDOM)

简单实现

{
type: 'div',
props: {
className: 'box',
children: 'Hello world',
}
} mountComponent(container) {
const domElement = document.createElement(this._currentElement.type);
const textNode = document.createTextNode(this._currentElement.props.children); domElement.appendChild(textNode);
container.appendChild(domElement);
return domElement;
}

ReactCompositeComponentWrapper 作用

这个类的mountComponent方法作用是:实例化自定义组件,最后是通过递归调用到ReactDOMComponentmountComponent方法来得到真实DOM。

渲染规则

最新文章

  1. Oracle 外网访问
  2. css设置img成圆形
  3. 【转】Android Studio系列教程六--Gradle多渠道打包
  4. 让用VS2012/VS2013编写的程序在XP中顺利运行
  5. Lua 5.1 参考手册
  6. IPv6协议
  7. Accessorizer的使用说明!
  8. MVC中JQuery文件引入的路径问题,@Url.Content函数
  9. ads 调试
  10. AIDL:Binder invocation to an incorrect interface
  11. 【C++学习之路】组合类的构造函数
  12. Unix/Linux环境C编程入门教程(5) Red Hat Enterprise Linux(RHEL)环境搭建
  13. Java线程小记
  14. 子字符查找KMP算法 - 子串自匹配索引表
  15. MyBatis源码分析之环境准备篇
  16. Java高并发秒杀系统API之SSM框架集成swagger与AdminLTE
  17. R语言实现对基因组SNV进行注释
  18. kafka Centos7.2 单机集群搭建
  19. 章节八、3-如何用Chrome开发者工具查看元素
  20. 网络爬虫BeautifulSoup库的使用

热门文章

  1. ungetc--C语言中处理字符串常碰到的问题
  2. The server cannot be started because one or more of the ports are invalid. Open the server editor and correct the invalid ports.
  3. Html介绍,认识head标签
  4. 折腾vue--vue自定义组件(三)
  5. kettle文本文件写入数据库,简单进行数据清洗
  6. python3练习100题——002
  7. 全网小说免费阅读下载APP
  8. Codeforces Round #622(Div 2)C2. Skyscrapers (hard version)
  9. 42.MySQL数据库安装,及驱动程序选择
  10. 80端口被Microsoft-HTTPAPI/2.0占用怎么解决?