Fix profile page data reset on re-focus of window (#5311)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent
8ecfe89a6f
commit
2df8f4f145
@@ -158,9 +158,12 @@ const ProfileView = () => {
|
||||
}>();
|
||||
|
||||
const { reset } = formMethods;
|
||||
|
||||
const formInitializedRef = useRef(false);
|
||||
useEffect(() => {
|
||||
if (user)
|
||||
// The purpose of reset is to set the initial value obtained from tRPC.
|
||||
// `user` would change for many reasons (e.g. when viewer.me automatically fetches on window re-focus(a react query feature))
|
||||
if (user && !formInitializedRef.current) {
|
||||
formInitializedRef.current = true;
|
||||
reset({
|
||||
avatar: user?.avatar || "",
|
||||
username: user?.username || "",
|
||||
@@ -168,6 +171,7 @@ const ProfileView = () => {
|
||||
email: user?.email || "",
|
||||
bio: user?.bio || "",
|
||||
});
|
||||
}
|
||||
}, [reset, user]);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
|
||||
Reference in New Issue
Block a user