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
- On mount, the provider dynamically imports the SDK script from the CDN (or a custom
swishSdkUrl). - It calls
createSwish()with your options to initialize the SDK. - The resulting
SwishAppinstance is stored in React context. - Hooks like
useSwishread 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 renderSwishProvider 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 throughSwishProvider’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: