Thay đổi key của component khiến React unmount component cũ và mount component mới hoàn toàn, reset tất cả state.
- Kỹ thuật hữu ích để: reset form sau submit
<Form key={formKey} />, reset uncontrolled component khi data source thay đổi. - Đây là cách React có ý muốn để 'reset' component state từ bên ngoài.
Changing a component's key causes React to unmount the old instance and mount a completely new one, resetting all state.
- This is useful for: resetting a form after submission
<Form key={formKey} />, or resetting an uncontrolled component when its data source changes. - This is the intentional React pattern for resetting a component's state from outside.