Open reboottime opened 3 months ago
React updates the part that needs update, instead of removing and adding a new one, by Virtual DOM.
The virtual DOM is a giant object that supposed to render all their props and children. Which are also the same shape that are supposed to be rendered inside.
For example
key
applicationThough there is a re-rendering between the isCompany
value changes, the internal state of Input
preserves
If there is key
defined on element, the key
order takes priority.
Mounting: append to DOM tree
Re-rendering: update the DOM tree
unmounting: remove it from DOM tree
{
"type": "FormGroup",
"props": {
"id": "",
"controlId": "",
"children": {
"type": "div",
"props": {
"className": ""
},
"children": [
{
"type": "FormLabel",
"props": {
"className": ""
},
"children": "Label Text"
},
{
"type": "FormControl",
"props": {
"type": "text",
"placeholder": "Hello",
"className": ""
},
"children": []
},
{
"type": "FormText",
"props": {
"className": ""
},
"children": "Help text"
}
]
}
}
}
About
This article is a note of Mastering React Reconciliation - Advanced React course
React Reconciliation: how React decides which component should be rendered/ removed
key
attribute and whykey
is useful outside of list