SwishProvider. They return null or loading states while the SDK initializes.
useSwish
Returns the Swish SDK instance.
Return value
Throws an error if called outside a
SwishProvider.
If
window.swish exists (for example, the SDK was loaded via a script tag),
the hook returns the global instance instead of the context value.useSwishItem
Manage save state for a single product. Handles lookups, save/unsave, list editing, and variant changes.
Props
Return value
The hook automatically queries the API to determine if the product or variant is already saved. Providing
itemId directly skips this query.
Match policy
The hook always loads saved state at the product level - a single cache entry per product is shared across every variant-aware component on the page. Thematch prop decides what counts as “saved”:
"variant": only saved ifvariantIdmatches a saved item."product": saved if any variant of the product is saved. Use on collection cards that show a default variant but should reflect the product-level wishlist state."auto"(default): variant-match whenvariantIdis set, product-match otherwise.
match also affects what gets saved: with match: "product", save() ignores variantId and saves the product, so a card that just renders the default variant for display doesn’t create a variant-bound saved item. unsave() always targets the currently picked savedItemId.
useSwishItems
Load saved items with pagination.
Options
Return value
useSwishLists
Load the customer’s lists.
Return value
Automatically refetches when items or lists change (
item-lists-update, item-delete, list-create, list-update, list-delete).
useSwishItemCount
Track the total number of saved items.
Return value
Automatically refetches when items are created or deleted (
item-create, item-delete). loading matches swish.state.itemCount(): a badge that hides itself while loading will not blink empty on a later refetch. The last known count stays until the new number lands.
useSwishQuery
Generic hook for making Swish API calls with automatic refetching on events.
Parameters
When
refetch is true, the query re-runs on these default events: item-create, item-update, item-delete, item-lists-update, list-create, list-update, list-delete, token-update.
When refetch is an array, token-update is always included automatically.
Return value
useSwishIntent
Invoke a Swish intent and track its pending state. See the intents reference for available intents and their parameters.
Parameters
Return value
The response contains a
code field ("ok", "closed", or "error") and intent-specific data on success. See the intents reference for the response format.