Skip to content
On this page

useNewsletter

Definition

Composable for newsletter subscription.

Basic usage

ts
const { 
 isNewsletterSubscriber,
 newsletterStatus,
 confirmationNeeded,
 newsletterSubscribe,
 newsletterUnsubscribe,
 getNewsletterStatus 
} = useNewsletter();

Signature

ts
export function useNewsletter(): UseNewsletterReturn 

Return type

See UseNewsletterReturn
ts
export type UseNewsletterReturn = {
  /**
   * Subscribes the user to the newsletter
   * @param params {@link NewsletterInput}
   */
  newsletterSubscribe(params: NewsletterInput): Promise<void>;
  /**
   * Removes the email from the newsletter
   * @param email
   */
  newsletterUnsubscribe(email: string): Promise<void>;
  /**
   * Get newsletter status from the API call
   */
  getNewsletterStatus(): Promise<void>;
  /**
   * Indicates if the user is subscribed to the newsletter
   *
   * Returns `true` if the user is subscribed to the newsletter, `false` otherwise
   */
  isNewsletterSubscriber: ComputedRef<boolean>;
  /**
   * Newsletter status
   */
  newsletterStatus: Ref<NewsletterStatus>;
  /**
   * Inform about newsletter confirmation
   */
  confirmationNeeded: ComputedRef<boolean>;
};

Properties

NameTypeDescription
isNewsletterSubscriber
ComputedRef<boolean>
Indicates if the user is subscribed to the newsletterReturns `true` if the user is subscribed to the newsletter, `false` otherwise
newsletterStatus
Ref<NewsletterStatus>
Newsletter status
confirmationNeeded
ComputedRef<boolean>
Inform about newsletter confirmation

Methods

NameTypeDescription
newsletterSubscribe
Promise<void>
Subscribes the user to the newsletter
newsletterUnsubscribe
Promise<void>
Removes the email from the newsletter
getNewsletterStatus
Promise<void>
Get newsletter status from the API call
useNewsletter has loaded