feat: improve profile cache (again)

This commit is contained in:
2023-03-03 14:30:31 +00:00
parent 27edf5f592
commit 32549522d4
32 changed files with 316 additions and 472 deletions

View File

@ -0,0 +1,21 @@
import { useEffect, useSyncExternalStore } from "react";
import { MetadataCache } from "State/Users";
import { HexKey } from "@snort/nostr";
import { System } from "System";
import { UserCache } from "State/Users/UserCache";
export function useUserProfile(pubKey?: HexKey): MetadataCache | undefined {
const user = useSyncExternalStore<MetadataCache | undefined>(
h => UserCache.hook(h, pubKey),
() => UserCache.get(pubKey)
);
useEffect(() => {
if (pubKey) {
System.TrackMetadata(pubKey);
return () => System.UntrackMetadata(pubKey);
}
}, [pubKey]);
return user;
}