React-Daten-Hooks
Integrationsanleitung und API-Referenz: React-Daten-Hooks.
Diese ausführliche API-Referenz wird auf Englisch gepflegt und folgt dem verlinkten SDK-Quellcode. Beispiele mit Anwendungsvariablen benötigen Ihren Signer, Ihre Schlüssel, Ihren Speicher oder Ihre Oberfläche.
React hooks
import {
NostrDataProvider,
useProfile,
useNote,
useThread,
useEngagement,
useFollows,
useRelayList,
} from "nostr-wot-sdk/data/react";
<NostrDataProvider
relays={["wss://relay.damus.io", "wss://nos.lol"]}
profileAggregators={["wss://purplepag.es"]}
persistence={{ namespace: "myapp", ttlMs: 86400_000 }}
>
<App />
</NostrDataProvider>;
function ProfileCard({ pubkey }: { pubkey: string }) {
const profile = useProfile(pubkey); // SWR
if (!profile) return <Skeleton />;
return <h1>{profile.displayName ?? profile.name}</h1>;
}<NostrDataProvider> configures defaults (relays, aggregators, persistence) on mount. If you're using @nostr-wot/wot or nostr-wot-sdk, prefer <NostrSdkProvider> instead — it wraps <NostrDataProvider> and adds opt-in WoT context.
Session context
nostr-wot-sdk/data/react also hosts the shared session context — the single mount point for the active NostrSigner and the user's pubkey. It lives here (not in @nostr-wot/ui) so non-UI packages — DM hooks, blossom uploads, wallet/zap hooks — can read the signer from context without depending on the React UI package.
import {
NostrSessionProvider,
useSession,
useSigner,
usePubkey,
useLogin,
useLogout,
useKEKSigner,
} from "nostr-wot-sdk/data/react";
<NostrSessionProvider
initialSigner={someSigner /* optional — e.g. constructed at boot */}
onChange={({ signer, pubkey }) => /* mirror to your state */}
onLogout={async () => { /* clear app caches */ }}
>
<App />
</NostrSessionProvider>;| Hook | Returns |
|---|---|
useSession() | { signer, pubkey, isLoading, error, setSigner, logout } |
useSigner() | The active NostrSigner or null |
usePubkey() | The active hex pubkey or null |
useLogin() | (signer) => Promise<void> callback — set the active signer |
useLogout() | () => Promise<void> callback — drops the signer + runs onLogout |
useKEKSigner() | A narrow KEKSigner (NIP-44 encrypt + decrypt + pubkey) when the active signer supports NIP-44, else null |
useKEKSigner exists because some operations — DM cache-key derivation, wallet local-store encryption — need NIP-44 specifically and must skip signers that don't expose it (e.g. NIP-46 bunkers with restricted perms). The hook returns null instead of throwing, so consumers can branch on capability:
const kek = useKEKSigner();
if (!kek) return <p>Your signer doesn't support NIP-44 — encrypted-at-rest cache disabled.</p>;
const cacheKey = await getOrCreateCacheKey(kek.pubkey, kek);@nostr-wot/ui mounts and consumes this same context for its login flows, and re-exports the hooks for convenience. If you're only using nostr-wot-sdk/data (no UI), construct a signer yourself (from nostr-wot-sdk/signers) and call useLogin()(signer) to attach it.