40
loading...
This website collects cookies to deliver better user experience
key
attribute? Why we need to use this if everything is working perfectly? The answer is rather simple, Performance!key
id in both trees, they are the same element and will not be re-rendered from 0.<div>
<Counter />
</div>
<span>
<Counter />
</span>
<!-- before -->
<img src="images/image.svg" className="something" />
<!-- after -->
<img src="images/image.svg" className="another-something" />
className
.<!-- before -->
<div style={{color: "green", padding: "10px"}}></div>
<!-- after -->
<div style={{color: "orange", padding: "10px"}}></div>
color
style, and not padding.
<!-- tree1 -->
<ul>
<li>1</li>
<li>2</li>
</ul>
<!-- tree2 -->
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
<!-- tree1 -->
<ul>
<li>2</li>
<li>3</li>
</ul>
<!-- tree2 -->
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
keys
are important. Using keys we can have every item in a list have a unique identifier (ID) so React can easily detect who needs to be changed or not, re-rendering only the ones with changes.