Skip to content
Justice Tech School

Resetting State with key

Changing a key remounts a component and resets its state.

Example
function Page({ userId }) {
  return <Profile key={userId} id={userId} />;
}

Exercise

Reset trick.

<Profile ={userId} />

Quiz Test

What happens when the key changes?

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