Skip to content

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 ​

PropertyTypeDescription
stripeReadonly<Ref<Stripe | null>>The Stripe instance
loadingReadonly<Ref<boolean>>True while Stripe.js is loading
errorReadonly<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 VueStripeProvider in an app that does not install createVueStripe(), useStripe() throws a VueStripeProviderError: 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, the useConfirm* composables, ...). They inject the same instance, track loading / error, and handle the not-yet-loaded case, so use useStripe() for readiness and state rather than for calling stripe.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 ​