@samitouri / QOS-React-1 / commits / d8afd1c82e

[crud] Scaffold initial types (#31555)

Scaffolds the initial `useResourceEffect` dispatcher type. This will eventually be folded into `useEffect` et al as an overload. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31555). * #31523 * #31557 * #31556 * __->__ #31555

lauren committed Nov 15, 2024 at 17:49 UTC d8afd1c82e671662c6d1e998bad7fe524071bd56
2 files changed +18
packages/react-reconciler/src/ReactInternalTypes.js
+8
@@ -47,6 +47,7 @@ export type HookType =
47 | 'useRef'
48 | 'useEffect'
49 | 'useEffectEvent'
50 + | 'useResourceEffect'
51 | 'useInsertionEffect'
52 | 'useLayoutEffect'
53 | 'useCallback'
@@ -412,6 +413,13 @@ export type Dispatcher = {
413 deps: Array<mixed> | void | null,
414 ): void,
415 useEffectEvent?: <Args, F: (...Array<Args>) => mixed>(callback: F) => F,
416 + useResourceEffect?: (
417 + create: () => mixed,
418 + createDeps: Array<mixed> | void | null,
419 + update: ((resource: mixed) => void) | void,
420 + updateDeps: Array<mixed> | void | null,
421 + destroy: ((resource: mixed) => void) | void,
422 + ) => void,
423 useInsertionEffect(
424 create: () => (() => void) | void,
425 deps: Array<mixed> | void | null,
packages/react/src/ReactHooks.js
+10
@@ -226,6 +226,16 @@ export function useEffectEvent<Args, F: (...Array<Args>) => mixed>(
226 return dispatcher.useEffectEvent(callback);
227 }
228
229 +export function useResourceEffect(
230 + create: () => mixed,
231 + createDeps: Array<mixed> | void | null,
232 + update: ((resource: mixed) => void) | void,
233 + updateDeps: Array<mixed> | void | null,
234 + destroy: ((resource: mixed) => void) | void,
235 +): void {
236 + throw new Error('Not implemented.');
237 +}
238 +
239 export function useOptimistic<S, A>(
240 passthrough: S,
241 reducer: ?(S, A) => S,