@@ -32,6 +32,7 @@ import {
3232 enableLazyContextPropagation ,
3333 enableUseMutableSource ,
3434 enableTransitionTracing ,
35+ enableUseMemoCacheHook ,
3536} from 'shared/ReactFeatureFlags' ;
3637
3738import {
@@ -721,6 +722,10 @@ function createFunctionComponentUpdateQueue(): FunctionComponentUpdateQueue {
721722 } ;
722723}
723724
725+ function useMemoCache ( size : number ) : Array < any > {
726+ throw new Error ( 'Not implemented.' ) ;
727+ }
728+
724729function basicStateReducer < S > (state: S, action: BasicStateAction< S > ): S {
725730 // $FlowFixMe: Flow doesn't like mixed types
726731 return typeof action === 'function' ? action ( state ) : action ;
@@ -2416,6 +2421,9 @@ if (enableCache) {
24162421 ( ContextOnlyDispatcher : Dispatcher ) . getCacheForType = getCacheForType ;
24172422 ( ContextOnlyDispatcher : Dispatcher ) . useCacheRefresh = throwInvalidHookError ;
24182423}
2424+ if (enableUseMemoCacheHook) {
2425+ ( ContextOnlyDispatcher : Dispatcher ) . useMemoCache = throwInvalidHookError ;
2426+ }
24192427
24202428const HooksDispatcherOnMount: Dispatcher = {
24212429 readContext ,
@@ -2444,6 +2452,9 @@ if (enableCache) {
24442452 ( HooksDispatcherOnMount : Dispatcher ) . getCacheForType = getCacheForType ;
24452453 ( HooksDispatcherOnMount : Dispatcher ) . useCacheRefresh = mountRefresh ;
24462454}
2455+ if (enableUseMemoCacheHook) {
2456+ ( HooksDispatcherOnMount : Dispatcher ) . useMemoCache = useMemoCache ;
2457+ }
24472458const HooksDispatcherOnUpdate: Dispatcher = {
24482459 readContext ,
24492460
@@ -2471,6 +2482,9 @@ if (enableCache) {
24712482 ( HooksDispatcherOnUpdate : Dispatcher ) . getCacheForType = getCacheForType ;
24722483 ( HooksDispatcherOnUpdate : Dispatcher ) . useCacheRefresh = updateRefresh ;
24732484}
2485+ if (enableUseMemoCacheHook) {
2486+ ( HooksDispatcherOnUpdate : Dispatcher ) . useMemoCache = useMemoCache ;
2487+ }
24742488
24752489const HooksDispatcherOnRerender: Dispatcher = {
24762490 readContext ,
@@ -2499,6 +2513,9 @@ if (enableCache) {
24992513 ( HooksDispatcherOnRerender : Dispatcher ) . getCacheForType = getCacheForType ;
25002514 ( HooksDispatcherOnRerender : Dispatcher ) . useCacheRefresh = updateRefresh ;
25012515}
2516+ if (enableUseMemoCacheHook) {
2517+ ( HooksDispatcherOnRerender : Dispatcher ) . useMemoCache = useMemoCache ;
2518+ }
25022519
25032520let HooksDispatcherOnMountInDEV: Dispatcher | null = null;
25042521let HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher | null = null;
@@ -2674,6 +2691,9 @@ if (__DEV__) {
26742691 return mountRefresh ( ) ;
26752692 } ;
26762693 }
2694+ if (enableUseMemoCacheHook) {
2695+ ( HooksDispatcherOnMountInDEV : Dispatcher ) . useMemoCache = useMemoCache ;
2696+ }
26772697
26782698 HooksDispatcherOnMountWithHookTypesInDEV = {
26792699 readContext < T > ( context : ReactContext < T > ) : T {
@@ -2816,6 +2836,9 @@ if (__DEV__) {
28162836 return mountRefresh ( ) ;
28172837 } ;
28182838 }
2839+ if (enableUseMemoCacheHook) {
2840+ ( HooksDispatcherOnMountWithHookTypesInDEV : Dispatcher ) . useMemoCache = useMemoCache ;
2841+ }
28192842
28202843 HooksDispatcherOnUpdateInDEV = {
28212844 readContext < T > ( context : ReactContext < T > ) : T {
@@ -2958,6 +2981,9 @@ if (__DEV__) {
29582981 return updateRefresh ( ) ;
29592982 } ;
29602983 }
2984+ if (enableUseMemoCacheHook) {
2985+ ( HooksDispatcherOnUpdateInDEV : Dispatcher ) . useMemoCache = useMemoCache ;
2986+ }
29612987
29622988 HooksDispatcherOnRerenderInDEV = {
29632989 readContext < T > ( context : ReactContext < T > ) : T {
@@ -3101,6 +3127,9 @@ if (__DEV__) {
31013127 return updateRefresh ( ) ;
31023128 } ;
31033129 }
3130+ if (enableUseMemoCacheHook) {
3131+ ( HooksDispatcherOnRerenderInDEV : Dispatcher ) . useMemoCache = useMemoCache ;
3132+ }
31043133
31053134 InvalidNestedHooksDispatcherOnMountInDEV = {
31063135 readContext < T > ( context : ReactContext < T > ) : T {
@@ -3260,6 +3289,14 @@ if (__DEV__) {
32603289 return mountRefresh ( ) ;
32613290 } ;
32623291 }
3292+ if (enableUseMemoCacheHook) {
3293+ ( InvalidNestedHooksDispatcherOnMountInDEV : Dispatcher ) . useMemoCache = function (
3294+ size : number ,
3295+ ) : Array < any > {
3296+ warnInvalidHookAccess ( ) ;
3297+ return useMemoCache ( size ) ;
3298+ } ;
3299+ }
32633300
32643301 InvalidNestedHooksDispatcherOnUpdateInDEV = {
32653302 readContext < T > (context: ReactContext< T > ): T {
@@ -3419,6 +3456,14 @@ if (__DEV__) {
34193456 return updateRefresh ( ) ;
34203457 } ;
34213458 }
3459+ if (enableUseMemoCacheHook) {
3460+ ( InvalidNestedHooksDispatcherOnUpdateInDEV : Dispatcher ) . useMemoCache = function (
3461+ size : number ,
3462+ ) : Array < any > {
3463+ warnInvalidHookAccess ( ) ;
3464+ return useMemoCache ( size ) ;
3465+ } ;
3466+ }
34223467
34233468 InvalidNestedHooksDispatcherOnRerenderInDEV = {
34243469 readContext < T > (context: ReactContext< T > ): T {
@@ -3579,4 +3624,12 @@ if (__DEV__) {
35793624 return updateRefresh ( ) ;
35803625 } ;
35813626 }
3627+ if (enableUseMemoCacheHook) {
3628+ ( InvalidNestedHooksDispatcherOnRerenderInDEV : Dispatcher ) . useMemoCache = function (
3629+ size : number ,
3630+ ) : Array < any > {
3631+ warnInvalidHookAccess ( ) ;
3632+ return useMemoCache ( size ) ;
3633+ } ;
3634+ }
35823635}
0 commit comments