Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kivircik-parantez/143f2a2574b846b2858ca3d8da3f63dc to your computer and use it in GitHub Desktop.
Save kivircik-parantez/143f2a2574b846b2858ca3d8da3f63dc to your computer and use it in GitHub Desktop.
Resetting all state when a prop changes
export default function ProfilePage({ userId }) {
return (
<Profile
userId={userId}
key={userId}
/>
);
}
function Profile({ userId }) {
// ✅ This and any other state below will reset on key change automatically
const [comment, setComment] = useState('');
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment