@strimz/sdk-react 0.2.8 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,6 +36,7 @@ export function useStrimzSession(
36
36
  const [loading, setLoading] = React.useState<boolean>(false)
37
37
  const [error, setError] = React.useState<Error | null>(null)
38
38
  const cancelledRef = React.useRef(false)
39
+ const sessionRef = React.useRef<PaymentSession | null>(null)
39
40
 
40
41
  const fetchOnce = React.useCallback(async () => {
41
42
  if (!sessionId) return
@@ -45,6 +46,7 @@ export function useStrimzSession(
45
46
  // The publishable-key client exposes them via `client.checkout.session`.
46
47
  const next = await client.checkout.session(sessionId)
47
48
  if (!cancelledRef.current) {
49
+ sessionRef.current = next
48
50
  setSession(next)
49
51
  setError(null)
50
52
  }
@@ -57,12 +59,14 @@ export function useStrimzSession(
57
59
 
58
60
  React.useEffect(() => {
59
61
  cancelledRef.current = false
62
+ sessionRef.current = null
60
63
  if (!sessionId) return
61
64
 
62
65
  void fetchOnce()
63
66
  const interval = options.pollIntervalMs ?? 3_000
64
67
  const timer = setInterval(() => {
65
- if (session && TERMINAL_STATES.includes(session.status)) return
68
+ const latest = sessionRef.current
69
+ if (latest && TERMINAL_STATES.includes(latest.status)) return
66
70
  void fetchOnce()
67
71
  }, interval)
68
72
 
@@ -70,8 +74,6 @@ export function useStrimzSession(
70
74
  cancelledRef.current = true
71
75
  clearInterval(timer)
72
76
  }
73
- // session is intentionally not in deps. The interval reads the latest via closure.
74
- // eslint-disable-next-line react-hooks/exhaustive-deps
75
77
  }, [sessionId, fetchOnce, options.pollIntervalMs])
76
78
 
77
79
  return { session, loading, error, refresh: fetchOnce }
package/src/index.ts CHANGED
@@ -36,3 +36,4 @@ export {
36
36
  type StrimzCheckoutEmbedProps,
37
37
  type StrimzCheckoutTheme,
38
38
  } from './components/StrimzCheckoutEmbed.js'
39
+ export { StrimzCheckoutError } from './checkout-error.js'