mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2025-08-26 20:49:22 +00:00
Add useAuthor code snippet to CONTEXT.md
This commit is contained in:
parent
246ffb2181
commit
1a431c9d8a
47
CONTEXT.md
47
CONTEXT.md
@ -117,6 +117,53 @@ function usePosts() {
|
||||
|
||||
The data may be transformed into a more appropriate format if needed, and multiple calls to `nostr.query()` may be made in a single queryFn.
|
||||
|
||||
### The `useAuthor` Hook
|
||||
|
||||
To display profile data for a user by their Nostr pubkey (such as an event author), use the `useAuthor` hook.
|
||||
|
||||
```tsx
|
||||
import { NostrEvent, NostrMetadata } from '@nostrify/nostrify';
|
||||
import { useAuthor } from '@/hooks/useAuthor';
|
||||
|
||||
function Post({ event }: { event: NostrEvent }) {
|
||||
const author = useAuthor(event.pubkey);
|
||||
const metadata: NostrMetadata | undefined = author.data?.metadata;
|
||||
|
||||
const displayName = metadata?.name || event.pubkey.slice(0, 8);
|
||||
const profileImage = metadata?.picture;
|
||||
|
||||
// ...render elements with this data
|
||||
}
|
||||
```
|
||||
|
||||
#### `NostrMetadata` type
|
||||
|
||||
```ts
|
||||
/** Kind 0 metadata. */
|
||||
interface NostrMetadata {
|
||||
/** A short description of the user. */
|
||||
about?: string;
|
||||
/** A URL to a wide (~1024x768) picture to be optionally displayed in the background of a profile screen. */
|
||||
banner?: string;
|
||||
/** A boolean to clarify that the content is entirely or partially the result of automation, such as with chatbots or newsfeeds. */
|
||||
bot?: boolean;
|
||||
/** An alternative, bigger name with richer characters than `name`. `name` should always be set regardless of the presence of `display_name` in the metadata. */
|
||||
display_name?: string;
|
||||
/** A bech32 lightning address according to NIP-57 and LNURL specifications. */
|
||||
lud06?: string;
|
||||
/** An email-like lightning address according to NIP-57 and LNURL specifications. */
|
||||
lud16?: string;
|
||||
/** A short name to be displayed for the user. */
|
||||
name?: string;
|
||||
/** An email-like Nostr address according to NIP-05. */
|
||||
nip05?: string;
|
||||
/** A URL to the user's avatar. */
|
||||
picture?: string;
|
||||
/** A web URL related in any way to the event author. */
|
||||
website?: string;
|
||||
}
|
||||
```
|
||||
|
||||
### The `useNostrPublish` Hook
|
||||
|
||||
To publish events, use the `useNostrPublish` hook in this project.
|
||||
|
Loading…
x
Reference in New Issue
Block a user