@reevit/react 0.2.7 → 0.2.8

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.
package/dist/index.mjs CHANGED
@@ -279,6 +279,7 @@ function useReevit(options) {
279
279
  const { config, onSuccess, onError, onClose, onStateChange, apiBaseUrl } = options;
280
280
  const [state, dispatch] = useReducer(reevitReducer, initialState);
281
281
  const apiClientRef = useRef(null);
282
+ const initializingRef = useRef(false);
282
283
  if (!apiClientRef.current) {
283
284
  apiClientRef.current = new ReevitAPIClient({
284
285
  publicKey: config.publicKey,
@@ -290,10 +291,15 @@ function useReevit(options) {
290
291
  }, [state.status, onStateChange]);
291
292
  const initialize = useCallback(
292
293
  async (method) => {
294
+ if (initializingRef.current) {
295
+ return;
296
+ }
297
+ initializingRef.current = true;
293
298
  dispatch({ type: "INIT_START" });
294
299
  try {
295
300
  const apiClient = apiClientRef.current;
296
301
  if (!apiClient) {
302
+ initializingRef.current = false;
297
303
  throw new Error("API client not initialized");
298
304
  }
299
305
  const reference = config.reference || generateReference();
@@ -317,6 +323,7 @@ function useReevit(options) {
317
323
  };
318
324
  dispatch({ type: "INIT_ERROR", payload: noDataError });
319
325
  onError?.(noDataError);
326
+ initializingRef.current = false;
320
327
  return;
321
328
  }
322
329
  const paymentIntent = mapToPaymentIntent(data, { ...config, reference });
@@ -330,6 +337,7 @@ function useReevit(options) {
330
337
  };
331
338
  dispatch({ type: "INIT_ERROR", payload: error });
332
339
  onError?.(error);
340
+ initializingRef.current = false;
333
341
  }
334
342
  },
335
343
  [config, onError, apiBaseUrl]
@@ -394,6 +402,7 @@ function useReevit(options) {
394
402
  [onError]
395
403
  );
396
404
  const reset = useCallback(() => {
405
+ initializingRef.current = false;
397
406
  dispatch({ type: "RESET" });
398
407
  }, []);
399
408
  const close = useCallback(async () => {