node_modules/@react-navigation/core/lib/module/useRouteCache.js
/**
 * Hook to cache route props for each screen in the navigator.
 * This lets add warnings and modifications to the route object but keep references between renders.
 */
Hook to cache route props for each screen in the navigator.
This lets add warnings and modifications to the route object but keep references between renders.
Hook to cache route props for each screen in the navigator . This lets add warnings and modifications to the route object but keep references between renders .
function useRouteCache(routes) {
  const cache = React.useMemo(() => ({
    current: new Map()
  }), []);
  if (process.env.NODE_ENV === 'production') {
    return routes;
  }
  cache.current = routes.reduce((acc, route) => {
    const previous = cache.current.get(route);
    if (previous) {
      acc.set(route, previous);
    } else {
      const proxy = { ...route
      };
      Object.defineProperty(proxy, 'state', {
        get() {
          if (!SUPPRESS_STATE_ACCESS_WARNING.value) {
            console.warn("Accessing the 'state' property of the 'route' object is not supported. If you want to get the focused route name, use the 'getFocusedRouteNameFromRoute' helper instead: https://reactnavigation.org/docs/5.x/screen-options-resolution/#setting-parent-screen-options-based-on-child-navigators-state");
          }
          return route.state;
        }
      });
      acc.set(route, proxy);
    }
    return acc;
  }, new Map());
  return Array.from(cache.current.values());
}
function useRouteCache ( routes ) { const cache = React . useMemo ( ( ) => ( { current : new Map ( ) } ) , [ ] ) ; if ( process . env . NODE_ENV === 'production' ) { return routes ; } cache . current = routes . reduce ( ( acc , route ) => { const previous = cache . current . get ( route ) ; if ( previous ) { acc . set ( route , previous ) ; } else { const proxy = { ... route } ; Object . defineProperty ( proxy , 'state' , { get ( ) { if ( ! SUPPRESS_STATE_ACCESS_WARNING . value ) { console . warn ( "Accessing the 'state' property of the 'route' object is not supported. If you want to get the focused route name, use the 'getFocusedRouteNameFromRoute' helper instead: https://reactnavigation.org/docs/5.x/screen-options-resolution/#setting-parent-screen-options-based-on-child-navigators-state" ) ; } return route . state ; } } ) ; acc . set ( route , proxy ) ; } return acc ; } , new Map ( ) ) ; return Array . from ( cache . current . values ( ) ) ; }
Hook to cache route props for each screen in the navigator.
Hook to cache route props for each screen in the navigator .
// Cache object which holds route objects for each screen // We don't want the overhead of creating extra maps every render in prod // If a cached route object already exists, reuse it