Skip to content
Justice Tech School

Keys and Resetting State

A different key makes React treat the element as new, so its state resets. Changing the key is a clean way to reset a form.

Example
<Profile key={userId} id={userId} />

Exercise

The attribute that resets state.

<Profile ={id} />

Quiz Test

What happens when key changes?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.