snort/src/feed/ProfileFeed.ts

18 lines
536 B
TypeScript
Raw Normal View History

2023-01-15 19:40:47 +00:00
import { useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import { HexKey } from "../nostr";
import { RootState } from "../state/Store";
import { addPubKey, MetadataCache } from "../state/Users";
export default function useProfile(pubKey: HexKey) {
const dispatch = useDispatch();
const user = useSelector<RootState, MetadataCache>(s => s.users.users[pubKey]);
useEffect(() => {
if (pubKey) {
dispatch(addPubKey(pubKey));
}
}, [pubKey]);
return user;
}