当前位置:网站首页>[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
边栏推荐
- Wechat applet development experience
- Excel导入,导出功能实现
- [algorithm] sword finger offer2 golang interview question 13: sum of numbers of two-dimensional submatrix
- Itext 7 生成PDF总结
- [algorithm] sword finger offer2 golang interview question 4: numbers that appear only once
- TYUT太原理工大学2022软工导论简答题
- TYUT太原理工大学2022数据库之关系代数小题
- GNSS positioning accuracy index calculation
- 初识C语言(下)
- 2-year experience summary, tell you how to do a good job in project management
猜你喜欢

Role movement in the first person perspective

TYUT太原理工大学2022数据库之关系代数小题

Record: the solution of MySQL denial of access when CMD starts for the first time

Alibaba cloud side: underlying details in concurrent scenarios - pseudo sharing

系统设计学习(二)Design a key-value cache to save the results of the most recent web server queries

十分钟彻底掌握缓存击穿、缓存穿透、缓存雪崩

What are the advantages of using SQL in Excel VBA

10 minutes pour maîtriser complètement la rupture du cache, la pénétration du cache, l'avalanche du cache

TYUT太原理工大学2022数据库大题之E-R图转关系模式

String类
随机推荐
[算法] 剑指offer2 golang 面试题8:和大于或等于k的最短子数组
First acquaintance with C language (Part 1)
MYSQL索引钟B-TREE ,B+TREE ,HASH索引之间的区别和应用场景
First acquaintance with C language (Part 2)
wsl常用命令
Error: sorting and subscript out of bounds
Error: symbol not found
错误: 找不到符号
Small exercise of library management system
十分钟彻底掌握缓存击穿、缓存穿透、缓存雪崩
Branch and loop statements
服务未正常关闭导致端口被占用
TYUT太原理工大学2022数据库大题之E-R图转关系模式
Excel导入,导出功能实现
[算法] 剑指offer2 golang 面试题9:乘积小于k的子数组
WSL common commands
Fairygui bar subfamily (scroll bar, slider, progress bar)
微信小程序开发心得
基本Dos命令
Exception: ioexception:stream closed