Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
pasyukevich committed Jul 17, 2024
1 parent a1b3496 commit 3ffa6de
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/libs/Navigation/AppNavigator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import React, {lazy, memo, Suspense, useContext, useEffect} from 'react';
import {NativeModules} from 'react-native';
import {InitialURLContext} from '@components/InitialURLContextProvider';
import Navigation from '@libs/Navigation/Navigation';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import lazyRetry from '@src/utils/lazyRetry';

const AuthScreens = lazy(() => lazyRetry(() => import('./AuthScreens')));
const PublicScreens = lazy(() => lazyRetry(() => import('./PublicScreens')));
const AuthScreens = lazy(() => lazyRetry<EmptyObject>(() => import('./AuthScreens')));
const PublicScreens = lazy(() => lazyRetry<EmptyObject>(() => import('./PublicScreens')));

type AppNavigatorProps = {
/** If we have an authToken this is true */
Expand Down
6 changes: 3 additions & 3 deletions src/utils/lazyRetry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {ComponentType, LazyExoticComponent} from 'react';
import type {ComponentType} from 'react';

type ComponentImport = () => Promise<{default: LazyExoticComponent<ComponentType>}>;
type ComponentImport<T> = () => Promise<{default: ComponentType<T>}>;

/**
* Attempts to lazily import a React component with a retry mechanism on failure.
Expand All @@ -10,7 +10,7 @@ type ComponentImport = () => Promise<{default: LazyExoticComponent<ComponentType
* @param componentImport - A function that returns a promise resolving to a lazily imported React component.
* @returns A promise that resolves to the imported component or rejects with an error after a retry attempt.
*/
const lazyRetry = function (componentImport: ComponentImport): Promise<{default: LazyExoticComponent<ComponentType>}> {
const lazyRetry = function <T>(componentImport: ComponentImport<T>): Promise<{default: ComponentType<T>}> {
return new Promise((resolve, reject) => {
// Retrieve the retry status from sessionStorage, defaulting to 'false' if not set
const hasRefreshed: unknown = JSON.parse(sessionStorage.getItem('retry-lazy-refreshed') ?? 'false');
Expand Down

0 comments on commit 3ffa6de

Please sign in to comment.