nostr-react icon indicating copy to clipboard operation
nostr-react copied to clipboard

useProfile seems to use the most recently received event, rather than the most recently created event.

Open michaelhall923 opened this issue 3 years ago • 1 comments

I noticed this behavior when trying to create a profile page with my picture on it.

export default function Profile() {
  const router = useRouter();
  const { pubkey } = router.query;

  const { data: userData } = useProfile({
    pubkey,
  });

  return (
    <>
      <Avatar
        src={userData?.picture}
        alt={userData?.name}
        size={42}
        radius="50%"
      />
      <Text size="lg" color="white">
        {userData?.display_name
          ? userData.display_name
          : `@${pubkey.substring(0, 5)}...`}
      </Text>
    </>
  );
}

The picture would initially load as my current picture, then after a few seconds switch to an old profile pic I used. This can be resolved by always setting userData to the event with the most recent created_at time.

michaelhall923 avatar Feb 10 '23 05:02 michaelhall923

Perhaps in useProfile, before executing setFetchedProfiles, we need to check whether fetchedProfiles[pubkey] already exists; if so, look at created_at to decide whether to update it or not.

wds4 avatar Feb 10 '23 21:02 wds4