State that Math.random() is not a good way to generate keys
Iurii Kucherov committed
Nov 5, 2015 at 14:37 UTC
30ca6619dce7597b792771804486646ae10ec733
1 file changed
+1
-1
docs/docs/ref-08-reconciliation.md
+1
-1
@@ -129,5 +129,5 @@ Because we rely on two heuristics, if the assumptions behind them are not met, p
129
130
1. The algorithm will not try to match sub-trees of different components classes. If you see yourself alternating between two components classes with very similar output, you may want to make it the same class. In practice, we haven't found this to be an issue.
131
132
-2. If you don't provide stable keys (by using Math.random() for example), all the sub-trees are going to be re-rendered every single time. By giving the users the choice to choose the key, they have the ability to shoot themselves in the foot.
132
+2. Keys should be stable, predictable, and unique. Unstable keys (like those produced by Math.random()) will cause many nodes to be unnecessarily re-created, which can cause performance degradation and lost state in child components.
133