Skip to content

Commit 9d9912e

Browse files
committed
componentsByName added
1 parent 1d462c0 commit 9d9912e

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>,
@@ -73,17 +81,13 @@ export function StackContainer({ routeConfigs }: StackContainerProps) {
7381
setRouteOptions: navMethods.setRouteOptions,
7482
};
7583

76-
const matchingConfig = routeConfigs.find(
77-
config => config.name === name,
78-
);
79-
if (!matchingConfig) {
84+
const Component = componentsByName.get(name);
85+
if (!Component) {
8086
throw new Error(
8187
`[Stack] No config matches the "${name}" route name`,
8288
);
8389
}
8490

85-
const Component = matchingConfig.Component;
86-
8791
return (
8892
<Stack.Screen
8993
key={routeKey}

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

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

3535
useSanitizeRouteConfigs(routeConfigs);
3636

37+
const componentsByName = React.useMemo(() => {
38+
const map = new Map<string, TabRouteConfig['Component']>();
39+
for (const config of routeConfigs) {
40+
map.set(config.name, config.Component);
41+
}
42+
return map;
43+
}, [routeConfigs]);
44+
3745
const [tabsNavState, dispatch]: [
3846
TabsContainerState,
3947
React.Dispatch<TabsNavigationAction>,
@@ -84,17 +92,13 @@ export function TabsContainer(props: TabsContainerProps) {
8492
const pendingForUpdate =
8593
route.routeKey === tabsNavState.suggestedState.selectedRouteKey;
8694

87-
const matchingConfig = routeConfigs.find(
88-
config => config.name === route.name,
89-
);
90-
if (!matchingConfig) {
95+
const Component = componentsByName.get(route.name);
96+
if (!Component) {
9197
throw new Error(
9298
`[Tabs] None config matches the "${route.name}" route name`,
9399
);
94100
}
95101

96-
const Component = matchingConfig.Component;
97-
98102
return (
99103
<TabsContainerItem
100104
key={route.routeKey}

0 commit comments

Comments
 (0)