@jokkoo/sdk-react 0.1.0 → 0.1.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.
package/dist/index.mjs CHANGED
@@ -492,7 +492,15 @@ function JokkooProvider({
492
492
  }
493
493
  const queryClient = externalQueryClient ?? internalQueryClientRef.current;
494
494
  const translations = useMemo(() => getTranslations(locale), [locale]);
495
- const apiClient = useMemo(() => {
495
+ const configKey = [
496
+ clientToken,
497
+ baseUrl ?? "",
498
+ locale ?? "",
499
+ String(debug ?? false),
500
+ String(tokenRefreshBufferSeconds ?? "")
501
+ ].join("\0");
502
+ const clientsRef = useRef2(null);
503
+ if (clientsRef.current?.configKey !== configKey || !Jokkoo.isInitialized()) {
496
504
  Jokkoo.init({
497
505
  clientToken,
498
506
  baseUrl,
@@ -501,10 +509,15 @@ function JokkooProvider({
501
509
  tokenRefreshBufferSeconds,
502
510
  userTokenProvider: () => tokenProviderRef.current()
503
511
  });
504
- void Jokkoo.getRealtimeClient().connect();
505
- return new JokkooApiClient(Jokkoo.getConfig(), Jokkoo.getTokenManager());
506
- }, [clientToken, baseUrl, locale, debug, tokenRefreshBufferSeconds]);
507
- const realtimeClient = useMemo(() => Jokkoo.getRealtimeClient(), [apiClient]);
512
+ const realtimeClient2 = Jokkoo.getRealtimeClient();
513
+ void realtimeClient2.connect();
514
+ clientsRef.current = {
515
+ configKey,
516
+ apiClient: new JokkooApiClient(Jokkoo.getConfig(), Jokkoo.getTokenManager()),
517
+ realtimeClient: realtimeClient2
518
+ };
519
+ }
520
+ const { apiClient, realtimeClient } = clientsRef.current;
508
521
  const { unreadCount, markConversationRead, isConversationUnread } = useGlobalRealtimeListener({
509
522
  apiClient,
510
523
  realtimeClient,
@@ -514,9 +527,10 @@ function JokkooProvider({
514
527
  });
515
528
  useEffect2(() => {
516
529
  return () => {
530
+ clientsRef.current = null;
517
531
  Jokkoo.destroy();
518
532
  };
519
- }, []);
533
+ }, [configKey]);
520
534
  const resetNavigation = useCallback2(() => {
521
535
  setCurrentScreen(initialScreen);
522
536
  setIsExpanded(false);