Loading
Die Vorschau läuft mit Beispieldaten. Sie braucht weder Netzwerk noch Kanal.
tsx
import { useYuvaSubscribe } from "@/hooks/use-yuva-subscribe"
export function Lists() {
const { lists, states, setSubscribed } = useYuvaSubscribe({
server={process.env.NEXT_PUBLIC_YUVA_SERVER}
channel={process.env.NEXT_PUBLIC_YUVA_CHANNEL},
})
return (
<ul>
{lists.map((list) => (
<li key={list.id}>
{list.name}
<button onClick={() => void setSubscribed(list.id, states[list.id] !== "subscribed", "I agree")}>
{states[list.id] === "subscribed" ? "Unsubscribe" : "Subscribe"}
</button>
</li>
))}
</ul>
)
}Installation
Führen Sie das in einem shadcn-Projekt aus. Die Dateien werden in Ihren eigenen Code kopiert.
Shell
npx shadcn@latest add https://useyuva.com/r/use-yuva-subscribe.jsonShell
pnpm dlx shadcn@latest add https://useyuva.com/r/use-yuva-subscribe.jsonShell
yarn dlx shadcn@latest add https://useyuva.com/r/use-yuva-subscribe.jsonShell
bunx --bun shadcn@latest add https://useyuva.com/r/use-yuva-subscribe.jsonVerwendung
tsx
import { useYuvaSubscribe } from "@/hooks/use-yuva-subscribe"
const { lists, states, subscribe, setSubscribed } = useYuvaSubscribe({ server, channel })Props
UseYuvaSubscribeOptions
| Prop | Typ |
|---|---|
server? | string |
channel? | string |
client? | YuvaClient |
identityToken? | IdentityTokenSource | null |
lists? | string[] |
YuvaSubscribeState
| Prop | Typ |
|---|---|
inboxName | string |
lists | ClientMailingList[] |
states | Record<string, SubscriptionState | undefined> |
identified | boolean |
loading | boolean |
error | unknown |
subscribe | (input: YuvaSubscribeInput) => Promise<{ confirmation: boolean }> |
setSubscribed | (listId: string, on: boolean, consentText: string) => Promise<SubscriptionState> |
Abhängigkeiten
Die Installation dieses Elements fügt auch Folgendes hinzu.