react 渲染
2024-09-04 07:38:24
目录
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的三个参数
type -> 标签
attributes => 属性标签,没有的话,可以为null
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
方法作用是:实例化自定义组件,最后是通过递归调用到ReactDOMComponent
的mountComponent
方法来得到真实DOM。
渲染规则
最新文章
- Oracle 外网访问
- css设置img成圆形
- 【转】Android Studio系列教程六--Gradle多渠道打包
- 让用VS2012/VS2013编写的程序在XP中顺利运行
- Lua 5.1 参考手册
- IPv6协议
- Accessorizer的使用说明!
- MVC中JQuery文件引入的路径问题,@Url.Content函数
- ads 调试
- AIDL:Binder invocation to an incorrect interface
- 【C++学习之路】组合类的构造函数
- Unix/Linux环境C编程入门教程(5) Red Hat Enterprise Linux(RHEL)环境搭建
- Java线程小记
- 子字符查找KMP算法 - 子串自匹配索引表
- MyBatis源码分析之环境准备篇
- Java高并发秒杀系统API之SSM框架集成swagger与AdminLTE
- R语言实现对基因组SNV进行注释
- kafka Centos7.2 单机集群搭建
- 章节八、3-如何用Chrome开发者工具查看元素
- 网络爬虫BeautifulSoup库的使用
热门文章
- ungetc--C语言中处理字符串常碰到的问题
- The server cannot be started because one or more of the ports are invalid. Open the server editor and correct the invalid ports.
- Html介绍,认识head标签
- 折腾vue--vue自定义组件(三)
- kettle文本文件写入数据库,简单进行数据清洗
- python3练习100题——002
- 全网小说免费阅读下载APP
- Codeforces Round #622(Div 2)C2. Skyscrapers (hard version)
- 42.MySQL数据库安装,及驱动程序选择
- 80端口被Microsoft-HTTPAPI/2.0占用怎么解决?