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 1+ import React , { useMemo } from 'react' ;
2+ import type { StackRouteConfig } from '../stack' ;
3+ import type { TabRouteConfig } from '../tabs' ;
4+
5+ export const useComponentByName = (
6+ routeConfigs : StackRouteConfig [ ] | TabRouteConfig [ ] ,
7+ ) => {
8+ return useMemo ( ( ) => {
9+ const map = new Map < string , React . ComponentType > ( ) ;
10+
11+ for ( const config of routeConfigs ) {
12+ map . set ( config . name , config . Component ) ;
13+ }
14+
15+ return map ;
16+ } , [ routeConfigs ] ) ;
17+ } ;
Original file line number Diff line number Diff line change @@ -21,17 +21,12 @@ import {
2121 useRenderDebugInfo ,
2222} from 'react-native-screens/private' ;
2323import { useParentNavigationEffect } from './hooks/useParentNavigationEffect' ;
24+ import { useComponentByName } from '../shared/use-component-by-name' ;
2425
2526export function StackContainer ( { routeConfigs } : StackContainerProps ) {
2627 useSanitizeRouteConfigs ( routeConfigs ) ;
2728
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 ] ) ;
29+ const componentsByName = useComponentByName ( routeConfigs ) ;
3530
3631 const [ stackNavState , navActionDispatch ] : [
3732 StackNavigationState ,
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import {
2121} from './reducer' ;
2222import { RNSLog } from 'react-native-screens/private' ;
2323import { TabsContainerItem } from './TabsContainerItem' ;
24+ import { useComponentByName } from '../shared/use-component-by-name' ;
2425
2526export function TabsContainer ( props : TabsContainerProps ) {
2627 RNSLog . info ( 'TabsContainer render' ) ;
@@ -34,13 +35,7 @@ export function TabsContainer(props: TabsContainerProps) {
3435
3536 useSanitizeRouteConfigs ( routeConfigs ) ;
3637
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 ] ) ;
38+ const componentsByName = useComponentByName ( routeConfigs ) ;
4439
4540 const [ tabsNavState , dispatch ] : [
4641 TabsContainerState ,
You can’t perform that action at this time.
0 commit comments