Most React devs know to declare a key when iterating over an array


Most React devs know to declare a key when iterating over an array.

But there are 2 lessor known reasons to use keys:

1. To force a re-render on a master/detail layout
2. To "reset" a component by creating a new instance

Changing the key creates a new instance.

#reactjs
For more on #1: https://www.nikgraf.com/blog/using-reacts-key-attribute-to-remount-a-component

For more on #2: https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html

View original on X