Fix useQuery lifecycle anti-pattern (#2001)
This commit is contained in:
parent
a83783f008
commit
f96b3bf19a
@ -100,17 +100,15 @@ const AccountListRow = ({ account, ...props }) => {
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
// fetch updated names and photo ids since they might have changed since we were issued the JWTs
|
// fetch updated names and photo ids since they might have changed since we were issued the JWTs
|
||||||
const [name, setName] = useState(account.name)
|
const { data, error } = useQuery(USER,
|
||||||
const [photoId, setPhotoId] = useState(account.photoId)
|
|
||||||
useQuery(USER,
|
|
||||||
{
|
{
|
||||||
variables: { id: account.id },
|
variables: { id: account.id }
|
||||||
onCompleted ({ user: { name, photoId } }) {
|
|
||||||
if (photoId) setPhotoId(photoId)
|
|
||||||
if (name) setName(name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
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) => {
|
const onClick = async (e) => {
|
||||||
// prevent navigation
|
// prevent navigation
|
||||||
|
Loading…
x
Reference in New Issue
Block a user