Fix useQuery lifecycle anti-pattern (#2001)

This commit is contained in:
ekzyis 2025-03-20 17:46:19 -05:00 committed by GitHub
parent a83783f008
commit f96b3bf19a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -100,17 +100,15 @@ const AccountListRow = ({ account, ...props }) => {
const router = useRouter()
// fetch updated names and photo ids since they might have changed since we were issued the JWTs
const [name, setName] = useState(account.name)
const [photoId, setPhotoId] = useState(account.photoId)
useQuery(USER,
const { data, error } = useQuery(USER,
{
variables: { id: account.id },
onCompleted ({ user: { name, photoId } }) {
if (photoId) setPhotoId(photoId)
if (name) setName(name)
}
variables: { id: account.id }
}
)
if (error) console.error(`query for user ${account.id} failed:`, error)
const name = data?.user?.name || account.name
const photoId = data?.user?.photoId || account.photoId
const onClick = async (e) => {
// prevent navigation