当前位置:网站首页>[Topic terminator]
[Topic terminator]
2022-07-06 13:11:00 【Brother an Yu】
Write it at the front
CSDN Topic challenge No 1 period
Event details address :CSDN
The topic of the competition : Front end interview book
Join hands to build a front-end interview classic
Topic 1 : stay React Medium element ( element) And the component ( component) What's the difference? ?
answer :
In short , stay React Medium element ( Virtual DOM) Describes what you see on the screen DOM Elements .
To put it another way , stay React The middle element is in the page DOM The object representation of the element . stay React The component in is a function or a class , It can accept input and return an element .
Be careful : In the work , To improve development efficiency , Usually use JSX Grammar said React Elements ( fictitious DOM). At compile time , Turn it into a React. createElement Calling method .
Here we write the answer to question one .
Expand :
What is? React Of refs? Why are they important ?
refs Allow you to directly access DOM Element or component instance . To use them , You can add... To the component ref attribute .
If the value of this attribute is a callback function , It will accept the underlying DOM The mounted instance of an element or component as its first parameter . It can be stored in components .
export class App extends Component {
showResult ( ) {
console. log(this. input. value)
}
render ( ) {
return (
<div>
<input type="text" ref={input => this .input =input } />
< button onClick={this. showResult.bind(this)}> Display the results </ button>
</div>
);
}
}
If the attribute value is a string , React Will instantiate the object in the component refs Properties of the , Store an attribute with the same name , This attribute is for this DOM Reference to element . It can be through native DOM API Operate it .
export class App extends Component {
showResult( )
console .log ( this.refs.username.value)
rende
Topic two :
When calling setState When , What happened ?
answer :
When calling setState when , React The first thing to do is to pass it on to setState Object to the current state of the component , This will start a process called reconciliation ( reconciliation) The process of .
The ultimate goal of reconciliation is , Update in the most effective way according to this new status DOM.
So , React Will build a new React fictitious DOM Trees ( You can think of it as a page DOM The object representation of the element ).
Once you have this DOM Trees , To find out DOM How to respond to the new state and change , React Will link this new tree with the previous virtual DOM Trees compare .
To do so , React You will know the exact changes that have taken place , And by understanding the changes that have taken place , Update when absolutely necessary DOM, That is, the operation of DOM And the occupied space is minimized .
At the end
CSDN Topic challenge No 1 period
- Event details address :CSDN
边栏推荐
- WSL common commands
- TYUT太原理工大学2022数据库大题之分解关系模式
- 错误:排序与角标越界
- [dry goods] cycle slip detection of suggestions to improve the fixed rate of RTK ambiguity
- 记录:newInstance()过时的代替方法
- Introduction pointer notes
- Tyut Taiyuan University of technology 2022 introduction to software engineering
- [算法] 剑指offer2 golang 面试题5:单词长度的最大乘积
- Differences and application scenarios between MySQL index clock B-tree, b+tree and hash indexes
- Fairygui bar subfamily (scroll bar, slider, progress bar)
猜你喜欢
抽象类和接口
[algorithm] sword finger offer2 golang interview question 12: the sum of the left and right sub arrays is equal
Application architecture of large live broadcast platform
[算法] 剑指offer2 golang 面试题9:乘积小于k的子数组
架构师怎样绘制系统架构蓝图?
如何保障 MySQL 和 Redis 的数据一致性?
系统设计学习(三)Design Amazon‘s sales rank by category feature
[算法] 剑指offer2 golang 面试题4:只出现一次的数字
[algorithm] sword finger offer2 golang interview question 3: the number of 1 in the binary form of the first n numbers
[algorithm] sword finger offer2 golang interview question 8: the shortest subarray with a sum greater than or equal to K
随机推荐
[rtklib] preliminary practice of using robust adaptive Kalman filter under RTK
架构师怎样绘制系统架构蓝图?
系统设计学习(三)Design Amazon‘s sales rank by category feature
[算法] 剑指offer2 golang 面试题2:二进制加法
Inheritance and polymorphism (Part 2)
Record: I accidentally wrote a recursion next time
2022 National Games RE1 baby_ tree
初识C语言(上)
MYSQL索引钟B-TREE ,B+TREE ,HASH索引之间的区别和应用场景
Error: sorting and subscript out of bounds
How do architects draw system architecture blueprints?
Comparative analysis of the execution efficiency of MySQL 5.7 statistical table records
TYUT太原理工大学2022数据库考试题型大纲
雇佣收银员【差分约束】
TYUT太原理工大学2022数据库大题之分解关系模式
Fairygui bar subfamily (scroll bar, slider, progress bar)
[算法] 剑指offer2 golang 面试题13:二维子矩阵的数字之和
Record: the solution of MySQL denial of access when CMD starts for the first time
First acquaintance with C language (Part 2)
十分鐘徹底掌握緩存擊穿、緩存穿透、緩存雪崩