Loading
L'anteprima usa dati di esempio. Non richiede rete né canale.
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>
)
}Installazione
Esegui questo in un progetto shadcn. I file vengono copiati nel tuo codice.
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.jsonUtilizzo
tsx
import { useYuvaSubscribe } from "@/hooks/use-yuva-subscribe"
const { lists, states, subscribe, setSubscribed } = useYuvaSubscribe({ server, channel })Props
UseYuvaSubscribeOptions
| Prop | Tipo |
|---|---|
server? | string |
channel? | string |
client? | YuvaClient |
identityToken? | IdentityTokenSource | null |
lists? | string[] |
YuvaSubscribeState
| Prop | Tipo |
|---|---|
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> |
Dipendenze
Installare questo elemento aggiunge anche quanto segue.