Skip to content

Commit 6757f87

Browse files
committed
componentsByName added
1 parent ced4f0c commit 6757f87

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

apps/src/shared/gamma/containers/stack/StackContainer.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ import { useParentNavigationEffect } from './hooks/useParentNavigationEffect';
2525
export function StackContainer({ routeConfigs }: StackContainerProps) {
2626
useSanitizeRouteConfigs(routeConfigs);
2727

28+
const componentsByName = React.useMemo(() => {
29+
const map = new Map<string, StackRouteConfig['Component']>();
30+
for (const config of routeConfigs) {
31+
map.set(config.name, config.Component);
32+
}
33+
return map;
34+
}, [routeConfigs]);
35+
2836
const [stackNavState, navActionDispatch]: [
2937
StackNavigationState,
3038
React.Dispatch<NavigationAction>,
@@ -78,17 +86,13 @@ export function StackContainer({ routeConfigs }: StackContainerProps) {
7886
setRouteOptions: navMethods.setRouteOptions,
7987
};
8088

81-
const matchingConfig = routeConfigs.find(
82-
config => config.name === name,
83-
);
84-
if (!matchingConfig) {
89+
const Component = componentsByName.get(name);
90+
if (!Component) {
8591
throw new Error(
8692
`[Stack] No config matches the "${name}" route name`,
8793
);
8894
}
8995

90-
const Component = matchingConfig.Component;
91-
9296
return (
9397
<Stack.Screen
9498
key={routeKey}

apps/src/shared/gamma/containers/tabs/TabsContainer.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ export function TabsContainer(props: TabsContainerProps) {
2929

3030
useSanitizeRouteConfigs(routeConfigs);
3131

32+
const componentsByName = React.useMemo(() => {
33+
const map = new Map<string, TabRouteConfig['Component']>();
34+
for (const config of routeConfigs) {
35+
map.set(config.name, config.Component);
36+
}
37+
return map;
38+
}, [routeConfigs]);
39+
3240
const [tabsNavState, dispatch]: [
3341
TabsContainerState,
3442
React.Dispatch<TabsNavigationAction>,
@@ -79,17 +87,13 @@ export function TabsContainer(props: TabsContainerProps) {
7987
const pendingForUpdate =
8088
route.routeKey === tabsNavState.suggestedState.selectedRouteKey;
8189

82-
const matchingConfig = routeConfigs.find(
83-
config => config.name === route.name,
84-
);
85-
if (!matchingConfig) {
90+
const Component = componentsByName.get(route.name);
91+
if (!Component) {
8692
throw new Error(
8793
`[Tabs] No config matches the "${route.name}" route name`,
8894
);
8995
}
9096

91-
const Component = matchingConfig.Component;
92-
9397
return (
9498
<TabsContainerItem
9599
key={route.routeKey}

0 commit comments

Comments
 (0)