Skip to main content
SwishProvider loads the Swish SDK script, initializes it with your configuration, and provides the SDK instance to all child hooks via React context.
Both storefront and context are required. You need a Shopify Storefront API access token for storefront.accessToken - see the configuration reference for how to create one.

Props

options

The options prop accepts all createSwish() configuration options, plus an optional swishSdkUrl string that overrides the default CDN URL used to load the Swish SDK script. This is useful for self-hosting the SDK or pinning a specific version.

How it works

  1. On mount, the provider dynamically imports the SDK script from the CDN (or a custom swishSdkUrl).
  2. It calls createSwish() with your options to initialize the SDK.
  3. The resulting SwishApp instance is stored in React context.
  4. Hooks like useSwish read from this context to access the SDK.

Client-only initialization

The SDK intentionally runs client-side only to have no effect on initial render performance. All Swish state loads in the browser after mount. You can render SwishProvider in SSR and React Server Component contexts - the SDK simply skips initialization on the server and waits until the component hydrates on the client. Hooks return null or loading states until initialization completes:

Error handling

If SDK initialization fails, the error is available through SwishProvider’s internal context. Hooks that depend on the SDK gracefully return null or empty states rather than throwing. The provider also logs the error to the console for debugging: