useStripe
Returns the Stripe instance and its loading and error state. Call it in a component rendered inside VueStripeProvider, or anywhere in an app that installs createVueStripe(). How Vue Stripe works explains why it must run inside the provider.
Usage
vue
<!-- StripeStatus.vue, rendered inside VueStripeProvider -->
<script setup lang="ts">
import { computed } from 'vue'
import { useStripe } from '@vue-stripe/vue-stripe'
const { stripe, loading, error } = useStripe()
const ready = computed(() => !loading.value && !error.value && stripe.value !== null)
</script>
<template>
<p v-if="loading">Loading Stripe...</p>
<p v-else-if="error">{{ error }}</p>
<slot v-else-if="ready" />
</template>Return Value
| Property | Type | Description |
|---|---|---|
stripe | Readonly<Ref<Stripe | null>> | The Stripe instance |
loading | Readonly<Ref<boolean>> | True while Stripe.js is loading |
error | Readonly<Ref<string | null>> | Error message if loading failed |
initialize | () => Promise<void> | No-op kept for API consistency; initialization is handled by the provider. |
All return values are readonly refs - you can read their .value but cannot modify them.
Behaviour
- Throws outside a provider. Called outside
VueStripeProviderin an app that does not installcreateVueStripe(),useStripe()throws aVueStripeProviderError:useStripe must be called within a VueStripeProvider component or an app using createVueStripe(). Calling it in the same component that renders the provider counts as outside: call it in a child component. Troubleshoot common problems shows the fix. - Calling Stripe.js. Every Stripe.js method has a wrapping composable (
usePaymentIntent,useSetupIntent,useCreatePaymentMethod, theuseConfirm*composables, ...). They inject the same instance, trackloading/error, and handle the not-yet-loaded case, so useuseStripe()for readiness and state rather than for callingstripe.value.<method>()yourself.
TypeScript
vue
<script setup lang="ts">
import { useStripe } from '@vue-stripe/vue-stripe'
import type { UseStripeReturn } from '@vue-stripe/vue-stripe'
// stripe.value is typed as Stripe | null
const { stripe, loading, error }: UseStripeReturn = useStripe()
</script>
<template>
<p v-if="loading">Loading Stripe...</p>
<p v-else-if="error">{{ error }}</p>
<p v-else-if="stripe">Stripe.js is ready</p>
</template>See Also
- VueStripeProvider - The provider component
- createVueStripe - Provide Stripe app-wide
- useStripeElements - Access the Elements instance
- How Vue Stripe works - The provider chain
- How Stripe.js is loaded - When the instance becomes available
- Troubleshoot common problems - Provider and composable errors
