Skip to content

Hooks API

All hooks must be used within a <WishlistProvider>.

useWishlist

Returns the current wishlist state.

import { useWishlist } from "@simplersuite/wishlist-react";
function MyComponent() {
const { items, loading, error, isGuest, count } = useWishlist();
}
PropertyTypeDescription
itemsWishlistItem[]Current wishlist items
loadingbooleanTrue during initial fetch
errorError | nullLast error, if any
isGuestbooleanTrue if using guest mode
countnumberNumber of items

useWishlistActions

Returns mutation functions with optimistic updates.

import { useWishlistActions } from "@simplersuite/wishlist-react";
function MyComponent() {
const { addItem, removeItem, bulkRemove, refresh } = useWishlistActions();
// Add a product
await addItem("product_123", {
variantId: "variant_456",
metadata: { color: "blue" },
});
// Remove a product
await removeItem("product_123");
// Remove multiple products
await bulkRemove(["product_1", "product_2"]);
// Force refresh from server
await refresh();
}
FunctionParamsDescription
addItem(productId, options?)Add to wishlist (optimistic)
removeItem(productId)Remove from wishlist (optimistic)
bulkRemove(productIds[])Remove multiple items
refresh()Re-fetch from server

All mutation functions return a Promise and throw on API failure (after rolling back the optimistic update).

useWishlistShare

Returns sharing functionality.

import { useWishlistShare } from "@simplersuite/wishlist-react";
function ShareButton() {
const { createShareLink, shareUrl, loading } = useWishlistShare();
return (
<button onClick={() => createShareLink()} disabled={loading}>
{shareUrl ? "Link created!" : "Share Wishlist"}
</button>
);
}
PropertyTypeDescription
createShareLink() => Promise<string | null>Generate a share URL
shareUrlstring | nullLast generated share URL
loadingbooleanTrue while generating

useIsWishlisted

O(1) check whether a product is in the wishlist.

import { useIsWishlisted } from "@simplersuite/wishlist-react";
function ProductCard({ productId }) {
const isWishlisted = useIsWishlisted(productId);
return <span>{isWishlisted ? "In wishlist" : "Not in wishlist"}</span>;
}