File tree Expand file tree Collapse file tree
apps/src/shared/gamma/containers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,6 +25,14 @@ import { useParentNavigationEffect } from './hooks/useParentNavigationEffect';
2525export 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 }
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments