Created
December 30, 2022 20:39
-
-
Save kivircik-parantez/143f2a2574b846b2858ca3d8da3f63dc to your computer and use it in GitHub Desktop.
Resetting all state when a prop changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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