Skip to content

Commit 51ccfc6

Browse files
authored
fix(clerk-js): Add default value to payment method segment (#5882)
1 parent b7c51ba commit 51ccfc6

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

.changeset/nine-bats-design.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Fix and issue after paying with a new card where it was navigationg to existing payment sources and then complete checkout screen

packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
ConfirmCheckoutParams,
99
} from '@clerk/types';
1010
import type { SetupIntent } from '@stripe/stripe-js';
11-
import { useEffect, useMemo, useState } from 'react';
11+
import { useMemo, useState } from 'react';
1212

1313
import { useCheckoutContext } from '../../contexts';
1414
import { Box, Button, Col, descriptors, Form, localizationKeys, Text } from '../../customizables';
@@ -118,7 +118,6 @@ const CheckoutFormElements = ({
118118
const { organization } = useOrganization();
119119
const { subscriber, subscriberType } = useCheckoutContext();
120120

121-
const [paymentMethodSource, setPaymentMethodSource] = useState<PaymentMethodSource>('existing');
122121
const [isSubmitting, setIsSubmitting] = useState(false);
123122
const [submitError, setSubmitError] = useState<ClerkRuntimeError | ClerkAPIError | string | undefined>();
124123

@@ -130,9 +129,9 @@ const CheckoutFormElements = ({
130129
);
131130
const { data: paymentSources } = data || { data: [] };
132131

133-
useEffect(() => {
134-
setPaymentMethodSource(paymentSources.length > 0 ? 'existing' : 'new');
135-
}, [paymentSources]);
132+
const [paymentMethodSource, setPaymentMethodSource] = useState<PaymentMethodSource>(() =>
133+
paymentSources.length > 0 ? 'existing' : 'new',
134+
);
136135

137136
const confirmCheckout = async (params: ConfirmCheckoutParams) => {
138137
try {

0 commit comments

Comments
 (0)