Skip to content
On this page

useWishlist ​

Definition ​

Composable to manage wishlist

Basic usage ​

ts
const { 
 items,
 getCurrentPage,
 getTotalPagesCount,
 totalWishlistItemsCount,
 mergeWishlistProducts,
 getWishlistProducts,
 clearWishlist,
 changeCurrentPage 
} = useWishlist();

Signature ​

ts
export function useWishlist(): UseWishlistReturn 

Return type ​

See UseWishlistReturn
ts
export type UseWishlistReturn = {
  /**
   * Merge products with wishlist between async (API) and sync (localstorage) wishlists
   */
  mergeWishlistProducts(): void;
  /**
   * Get products list added to wishlist
   */
  getWishlistProducts(): void;
  /**
   * Clear wishlist
   */
  clearWishlist(): void;
  /**
   * Wishlist items (Product IDs)
   */
  items: ComputedRef<string[]>;
  /**
   * Changes the current page number
   * @param pageNumber - page number to change to
   * @returns
   */
  changeCurrentPage(
    page: number,
    query?: operations["searchPage post /search"]["body"],
  ): Promise<void>;
  /**
   * Current page number
   */
  getCurrentPage: ComputedRef<number>;
  /**
   * total pages count
   */
  getTotalPagesCount: ComputedRef<number>;
  /**
   * total wishlist items count
   */
  totalWishlistItemsCount: Ref<number>;
};

Properties ​

NameTypeDescription
items
ComputedRef<Array<string>>
Wishlist items (Product IDs)
getCurrentPage
ComputedRef<number>
Current page number
getTotalPagesCount
ComputedRef<number>
total pages count
totalWishlistItemsCount
Ref<number>
total wishlist items count

Methods ​

NameTypeDescription
mergeWishlistProducts
void
Merge products with wishlist between async (API) and sync (localstorage) wishlists
getWishlistProducts
void
Get products list added to wishlist
clearWishlist
void
Clear wishlist
changeCurrentPage
Promise<void>
Changes the current page number
useWishlist has loaded