[crud] Remove useResourceEffect

Removes useResourceEffect.
This commit is contained in:
Lauren Tan
2025-01-30 16:27:02 -05:00
parent 601b4ea932
commit 1b2207312d
9 changed files with 1 additions and 227 deletions
-22
View File
@@ -128,9 +128,6 @@ function getPrimitiveStackCache(): Map<string, Array<any>> {
Dispatcher.useId();
if (typeof Dispatcher.useResourceEffect === 'function') {
Dispatcher.useResourceEffect(() => ({}), []);
}
if (typeof Dispatcher.useEffectEvent === 'function') {
Dispatcher.useEffectEvent((args: empty) => {});
}
@@ -741,24 +738,6 @@ function useHostTransitionStatus(): TransitionStatus {
return status;
}
function useResourceEffect(
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
update: ((resource: {...} | void | null) => void) | void,
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
) {
nextHook();
hookLog.push({
displayName: null,
primitive: 'ResourceEffect',
stackError: new Error(),
value: create,
debugInfo: null,
dispatcherHookName: 'ResourceEffect',
});
}
function useEffectEvent<Args, F: (...Array<Args>) => mixed>(callback: F): F {
nextHook();
hookLog.push({
@@ -798,7 +777,6 @@ const Dispatcher: DispatcherType = {
useActionState,
useHostTransitionStatus,
useEffectEvent,
useResourceEffect,
};
// create a proxy to throw a custom error
-158
View File
@@ -3989,9 +3989,6 @@ export const ContextOnlyDispatcher: Dispatcher = {
if (enableUseEffectEventHook) {
(ContextOnlyDispatcher: Dispatcher).useEffectEvent = throwInvalidHookError;
}
if (enableUseEffectCRUDOverload) {
(ContextOnlyDispatcher: Dispatcher).useResourceEffect = throwInvalidHookError;
}
const HooksDispatcherOnMount: Dispatcher = {
readContext,
@@ -4022,9 +4019,6 @@ const HooksDispatcherOnMount: Dispatcher = {
if (enableUseEffectEventHook) {
(HooksDispatcherOnMount: Dispatcher).useEffectEvent = mountEvent;
}
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnMount: Dispatcher).useResourceEffect = mountResourceEffect;
}
const HooksDispatcherOnUpdate: Dispatcher = {
readContext,
@@ -4055,10 +4049,6 @@ const HooksDispatcherOnUpdate: Dispatcher = {
if (enableUseEffectEventHook) {
(HooksDispatcherOnUpdate: Dispatcher).useEffectEvent = updateEvent;
}
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnUpdate: Dispatcher).useResourceEffect =
updateResourceEffect;
}
const HooksDispatcherOnRerender: Dispatcher = {
readContext,
@@ -4089,10 +4079,6 @@ const HooksDispatcherOnRerender: Dispatcher = {
if (enableUseEffectEventHook) {
(HooksDispatcherOnRerender: Dispatcher).useEffectEvent = updateEvent;
}
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnRerender: Dispatcher).useResourceEffect =
updateResourceEffect;
}
let HooksDispatcherOnMountInDEV: Dispatcher | null = null;
let HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher | null = null;
@@ -4310,27 +4296,6 @@ if (__DEV__) {
return mountEvent(callback);
};
}
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnMountInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
update: ((resource: {...} | void | null) => void) | void,
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
): void {
currentHookNameInDev = 'useResourceEffect';
mountHookTypesDev();
checkDepsAreNonEmptyArrayDev(updateDeps);
return mountResourceEffect(
create,
createDeps,
update,
updateDeps,
destroy,
);
};
}
HooksDispatcherOnMountWithHookTypesInDEV = {
readContext<T>(context: ReactContext<T>): T {
@@ -4514,26 +4479,6 @@ if (__DEV__) {
return mountEvent(callback);
};
}
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
update: ((resource: {...} | void | null) => void) | void,
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
): void {
currentHookNameInDev = 'useResourceEffect';
updateHookTypesDev();
return mountResourceEffect(
create,
createDeps,
update,
updateDeps,
destroy,
);
};
}
HooksDispatcherOnUpdateInDEV = {
readContext<T>(context: ReactContext<T>): T {
@@ -4717,26 +4662,6 @@ if (__DEV__) {
return updateEvent(callback);
};
}
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnUpdateInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
update: ((resource: {...} | void | null) => void) | void,
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
) {
currentHookNameInDev = 'useResourceEffect';
updateHookTypesDev();
return updateResourceEffect(
create,
createDeps,
update,
updateDeps,
destroy,
);
};
}
HooksDispatcherOnRerenderInDEV = {
readContext<T>(context: ReactContext<T>): T {
@@ -4920,26 +4845,6 @@ if (__DEV__) {
return updateEvent(callback);
};
}
if (enableUseEffectCRUDOverload) {
(HooksDispatcherOnRerenderInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
update: ((resource: {...} | void | null) => void) | void,
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
) {
currentHookNameInDev = 'useResourceEffect';
updateHookTypesDev();
return updateResourceEffect(
create,
createDeps,
update,
updateDeps,
destroy,
);
};
}
InvalidNestedHooksDispatcherOnMountInDEV = {
readContext<T>(context: ReactContext<T>): T {
@@ -5148,27 +5053,6 @@ if (__DEV__) {
return mountEvent(callback);
};
}
if (enableUseEffectCRUDOverload) {
(InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
update: ((resource: {...} | void | null) => void) | void,
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
): void {
currentHookNameInDev = 'useResourceEffect';
warnInvalidHookAccess();
mountHookTypesDev();
return mountResourceEffect(
create,
createDeps,
update,
updateDeps,
destroy,
);
};
}
InvalidNestedHooksDispatcherOnUpdateInDEV = {
readContext<T>(context: ReactContext<T>): T {
@@ -5377,27 +5261,6 @@ if (__DEV__) {
return updateEvent(callback);
};
}
if (enableUseEffectCRUDOverload) {
(InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
update: ((resource: {...} | void | null) => void) | void,
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
) {
currentHookNameInDev = 'useResourceEffect';
warnInvalidHookAccess();
updateHookTypesDev();
return updateResourceEffect(
create,
createDeps,
update,
updateDeps,
destroy,
);
};
}
InvalidNestedHooksDispatcherOnRerenderInDEV = {
readContext<T>(context: ReactContext<T>): T {
@@ -5606,25 +5469,4 @@ if (__DEV__) {
return updateEvent(callback);
};
}
if (enableUseEffectCRUDOverload) {
(InvalidNestedHooksDispatcherOnRerenderInDEV: Dispatcher).useResourceEffect =
function useResourceEffect(
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
update: ((resource: {...} | void | null) => void) | void,
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
) {
currentHookNameInDev = 'useResourceEffect';
warnInvalidHookAccess();
updateHookTypesDev();
return updateResourceEffect(
create,
createDeps,
update,
updateDeps,
destroy,
);
};
}
}
-9
View File
@@ -47,7 +47,6 @@ export type HookType =
| 'useRef'
| 'useEffect'
| 'useEffectEvent'
| 'useResourceEffect'
| 'useInsertionEffect'
| 'useLayoutEffect'
| 'useCallback'
@@ -399,14 +398,6 @@ export type Dispatcher = {
): void,
// TODO: Non-nullable once `enableUseEffectEventHook` is on everywhere.
useEffectEvent?: <Args, F: (...Array<Args>) => mixed>(callback: F) => F,
// TODO: Non-nullable once `enableUseEffectCRUDOverload` is on everywhere.
useResourceEffect?: (
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
update: ((resource: {...} | void | null) => void) | void,
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
) => void,
useInsertionEffect(
create: () => (() => void) | void,
deps: Array<mixed> | void | null,
+1 -9
View File
@@ -38,10 +38,7 @@ import {
} from './ReactFizzConfig';
import {createFastHash} from './ReactServerStreamConfig';
import {
enableUseEffectEventHook,
enableUseEffectCRUDOverload,
} from 'shared/ReactFeatureFlags';
import {enableUseEffectEventHook} from 'shared/ReactFeatureFlags';
import is from 'shared/objectIs';
import {
REACT_CONTEXT_TYPE,
@@ -866,11 +863,6 @@ export const HooksDispatcher: Dispatcher = supportsClientAPIs
if (enableUseEffectEventHook) {
HooksDispatcher.useEffectEvent = useEffectEvent;
}
if (enableUseEffectCRUDOverload) {
HooksDispatcher.useResourceEffect = supportsClientAPIs
? noop
: clientHookNotSupported;
}
export let currentResumableState: null | ResumableState = (null: any);
export function setCurrentResumableState(
-1
View File
@@ -59,7 +59,6 @@ export {
useDeferredValue,
useEffect,
experimental_useEffectEvent,
experimental_useResourceEffect,
useImperativeHandle,
useInsertionEffect,
useLayoutEffect,
@@ -42,7 +42,6 @@ export {
useDeferredValue,
useEffect,
experimental_useEffectEvent,
experimental_useResourceEffect,
useImperativeHandle,
useInsertionEffect,
useLayoutEffect,
-1
View File
@@ -21,7 +21,6 @@ export {
createElement,
createRef,
experimental_useEffectEvent,
experimental_useResourceEffect,
forwardRef,
Fragment,
isValidElement,
-5
View File
@@ -41,7 +41,6 @@ import {
useContext,
useEffect,
useEffectEvent,
useResourceEffect,
useImperativeHandle,
useDebugValue,
useInsertionEffect,
@@ -65,7 +64,6 @@ import {addTransitionType} from './ReactTransitionType';
import {act} from './ReactAct';
import {captureOwnerStack} from './ReactOwnerStack';
import * as ReactCompilerRuntime from './ReactCompilerRuntime';
import {enableUseEffectCRUDOverload} from 'shared/ReactFeatureFlags';
const Children = {
map,
@@ -132,6 +130,3 @@ export {
act, // DEV-only
captureOwnerStack, // DEV-only
};
export const experimental_useResourceEffect: typeof useResourceEffect | void =
enableUseEffectCRUDOverload ? useResourceEffect : undefined;
-21
View File
@@ -221,27 +221,6 @@ export function useEffectEvent<Args, F: (...Array<Args>) => mixed>(
return dispatcher.useEffectEvent(callback);
}
export function useResourceEffect(
create: () => {...} | void | null,
createDeps: Array<mixed> | void | null,
update: ((resource: {...} | void | null) => void) | void,
updateDeps: Array<mixed> | void | null,
destroy: ((resource: {...} | void | null) => void) | void,
): void {
if (!enableUseEffectCRUDOverload) {
throw new Error('Not implemented.');
}
const dispatcher = resolveDispatcher();
// $FlowFixMe[not-a-function] This is unstable, thus optional
return dispatcher.useResourceEffect(
create,
createDeps,
update,
updateDeps,
destroy,
);
}
export function useOptimistic<S, A>(
passthrough: S,
reducer: ?(S, A) => S,