当前位置:网站首页>[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
边栏推荐
- [algorithme] swordfinger offer2 golang question d'entrevue 2: addition binaire
- 165. Compare version number - string
- 系统设计学习(一)Design Pastebin.com (or Bit.ly)
- Interview Essentials: talk about the various implementations of distributed locks!
- Chromatic judgement bipartite graph
- XV Function definition and call
- 微信小程序开发心得
- 4.30 dynamic memory allocation notes
- 2-year experience summary, tell you how to do a good job in project management
- RTKLIB: demo5 b34f. 1 vs b33
猜你喜欢

Small exercise of library management system

TYUT太原理工大学2022“mao gai”必背

系统设计学习(三)Design Amazon‘s sales rank by category feature

阿里云一面:并发场景下的底层细节 - 伪共享问题
![[algorithm] sword finger offer2 golang interview question 10: subarray with sum K](/img/63/7422489d09a64ec9f0e79378761bf1.png)
[algorithm] sword finger offer2 golang interview question 10: subarray with sum K

面试必备:聊聊分布式锁的多种实现!

Edit distance (multi-source BFS)

Rt-ppp test using rtknavi

微信小程序开发心得

Record: the solution of MySQL denial of access when CMD starts for the first time
随机推荐
4.30动态内存分配笔记
记录:newInstance()过时的代替方法
Shortest Hamilton path (pressure DP)
Fgui project packaging and Publishing & importing unity & the way to display the UI
Pride-pppar source code analysis
Realization of the code for calculating the mean square error of GPS Height Fitting
[Chongqing Guangdong education] Shandong University College Physics reference materials
系统设计学习(三)Design Amazon‘s sales rank by category feature
WSL common commands
How to ensure data consistency between MySQL and redis?
系统设计学习(一)Design Pastebin.com (or Bit.ly)
[algorithm] sword finger offer2 golang interview question 3: the number of 1 in the binary form of the first n numbers
【快趁你舍友打游戏,来看道题吧】
Basic DOS commands
First acquaintance with C language (Part 2)
Role movement in the first person perspective
面渣逆袭:Redis连环五十二问,三万字+八十图详解。
TYUT太原理工大学往年数据库简述题
初识C语言(下)
2年经验总结,告诉你如何做好项目管理