2523
tag: HookFlags,
2524
inst: EffectInstance,
2525
create: () => (() => void) | void,
2526
- deps: Array<mixed> | void | null,
2526
+ createDeps: Array<mixed> | void | null,
2527
+ update?: ((resource: {...} | void | null) => void) | void,
2528
+ updateDeps?: Array<mixed> | void | null,
2529
+ destroy?: ((resource: {...} | void | null) => void) | void,
2530
): Effect {
2531
const effect: Effect = {
2532
tag,
2533
create,
2531
- deps,
2534
+ deps: createDeps,
2535
inst,
2536
// Circular
2537
next: (null: any),
2611
fiberFlags: Flags,
2612
hookFlags: HookFlags,
2613
create: () => (() => void) | void,
2611
- deps: Array<mixed> | void | null,
2614
+ createDeps: Array<mixed> | void | null,
2615
+ update?: ((resource: {...} | void | null) => void) | void,
2616
+ updateDeps?: Array<mixed> | void | null,
2617
+ destroy?: ((resource: {...} | void | null) => void) | void,
2618
): void {
2619
const hook = mountWorkInProgressHook();
2614
- const nextDeps = deps === undefined ? null : deps;
2620
+ const nextDeps = createDeps === undefined ? null : createDeps;
2621
currentlyRenderingFiber.flags |= fiberFlags;
2622
hook.memoizedState = pushSimpleEffect(
2623
HookHasEffect | hookFlags,
2668
}
2669
2670
function mountEffect(
2665
- create: () => (() => void) | void,
2666
- deps: Array<mixed> | void | null,
2671
+ create: (() => (() => void) | void) | (() => {...} | void | null),
2672
+ createDeps: Array<mixed> | void | null,
2673
+ update?: ((resource: {...} | void | null) => void) | void,
2674
+ updateDeps?: Array<mixed> | void | null,
2675
+ destroy?: ((resource: {...} | void | null) => void) | void,
2676
): void {
2677
if (
2678
__DEV__ &&
2679
(currentlyRenderingFiber.mode & StrictEffectsMode) !== NoMode &&
2680
(currentlyRenderingFiber.mode & NoStrictPassiveEffectsMode) === NoMode
2681
) {
2673
- mountEffectImpl(
2674
- MountPassiveDevEffect | PassiveEffect | PassiveStaticEffect,
2675
- HookPassive,
2676
- create,
2677
- deps,
2678
- );
2682
+ if (
2683
+ enableUseEffectCRUDOverload &&
2684
+ (typeof update === 'function' || typeof destroy === 'function')
2685
+ ) {
2686
+ mountResourceEffectImpl(
2687
+ MountPassiveDevEffect | PassiveEffect | PassiveStaticEffect,
2688
+ HookPassive,
2689
+ create,
2690
+ createDeps,
2691
+ update,
2692
+ updateDeps,
2693
+ destroy,
2694
+ );
2695
+ } else {
2696
+ mountEffectImpl(
2697
+ MountPassiveDevEffect | PassiveEffect | PassiveStaticEffect,
2698
+ HookPassive,
2699
+ // $FlowFixMe[incompatible-call] @poteto it's not possible to narrow `create` without calling it.
2700
+ create,
2701
+ createDeps,
2702
+ );
2703
+ }
2704
} else {
2680
- mountEffectImpl(
2681
- PassiveEffect | PassiveStaticEffect,
2682
- HookPassive,
2683
- create,
2684
- deps,
2685
- );
2705
+ if (
2706
+ enableUseEffectCRUDOverload &&
2707
+ (typeof update === 'function' || typeof destroy === 'function')
2708
+ ) {
2709
+ mountResourceEffectImpl(
2710
+ PassiveEffect | PassiveStaticEffect,
2711
+ HookPassive,
2712
+ create,
2713
+ createDeps,
2714
+ update,
2715
+ updateDeps,
2716
+ destroy,
2717
+ );
2718
+ } else {
2719
+ mountEffectImpl(
2720
+ PassiveEffect | PassiveStaticEffect,
2721
+ HookPassive,
2722
+ // $FlowFixMe[incompatible-call] @poteto it's not possible to narrow `create` without calling it.
2723
+ create,
2724
+ createDeps,
2725
+ );
2726
+ }
2727
}
2728
}
2729
2730
function updateEffect(
2690
- create: () => (() => void) | void,
2691
- deps: Array<mixed> | void | null,
2731
+ create: (() => (() => void) | void) | (() => {...} | void | null),
2732
+ createDeps: Array<mixed> | void | null,
2733
+ update?: ((resource: {...} | void | null) => void) | void,
2734
+ updateDeps?: Array<mixed> | void | null,
2735
+ destroy?: ((resource: {...} | void | null) => void) | void,
2736
): void {
2693
- updateEffectImpl(PassiveEffect, HookPassive, create, deps);
2737
+ if (
2738
+ enableUseEffectCRUDOverload &&
2739
+ (typeof update === 'function' || typeof destroy === 'function')
2740
+ ) {
2741
+ updateResourceEffectImpl(
2742
+ PassiveEffect,
2743
+ HookPassive,
2744
+ create,
2745
+ createDeps,
2746
+ update,
2747
+ updateDeps,
2748
+ destroy,
2749
+ );
2750
+ } else {
2751
+ // $FlowFixMe[incompatible-call] @poteto it's not possible to narrow `create` without calling it.
2752
+ updateEffectImpl(PassiveEffect, HookPassive, create, createDeps);
2753
+ }
2754
}
2755
2756
function mountResourceEffect(
2765
(currentlyRenderingFiber.mode & StrictEffectsMode) !== NoMode &&
2766
(currentlyRenderingFiber.mode & NoStrictPassiveEffectsMode) === NoMode
2767
) {
2708
- mountResourceEffectImpl(
2709
- MountPassiveDevEffect | PassiveEffect | PassiveStaticEffect,
2710
- HookPassive,
2711
- create,
2712
- createDeps,
2713
- update,
2714
- updateDeps,
2715
- destroy,
2716
- );
2768
} else {
2769
mountResourceEffectImpl(
2770
PassiveEffect | PassiveStaticEffect,
4138
return readContext(context);
4139
},
4140
useEffect(
4090
- create: () => (() => void) | void,
4091
- deps: Array<mixed> | void | null,
4141
+ create: (() => (() => void) | void) | (() => {...} | void | null),
4142
+ createDeps: Array<mixed> | void | null,
4143
+ update?: ((resource: {...} | void | null) => void) | void,
4144
+ updateDeps?: Array<mixed> | void | null,
4145
+ destroy?: ((resource: {...} | void | null) => void) | void,
4146
): void {
4147
currentHookNameInDev = 'useEffect';
4148
mountHookTypesDev();
4095
- checkDepsAreArrayDev(deps);
4096
- return mountEffect(create, deps);
4149
+ if (
4150
+ enableUseEffectCRUDOverload &&
4151
+ (typeof update === 'function' || typeof destroy === 'function')
4152
+ ) {
4153
+ checkDepsAreNonEmptyArrayDev(updateDeps);
4154
+ return mountResourceEffect(
4155
+ create,
4156
+ createDeps,
4157
+ update,
4158
+ updateDeps,
4159
+ destroy,
4160
+ );
4161
+ } else {
4162
+ checkDepsAreArrayDev(createDeps);
4163
+ return mountEffect(create, createDeps);
4164
+ }
4165
},
4166
useImperativeHandle<T>(
4167
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
4348
return readContext(context);
4349
},
4350
useEffect(
4283
- create: () => (() => void) | void,
4284
- deps: Array<mixed> | void | null,
4351
+ create: (() => (() => void) | void) | (() => {...} | void | null),
4352
+ createDeps: Array<mixed> | void | null,
4353
+ update?: ((resource: {...} | void | null) => void) | void,
4354
+ updateDeps?: Array<mixed> | void | null,
4355
+ destroy?: ((resource: {...} | void | null) => void) | void,
4356
): void {
4357
currentHookNameInDev = 'useEffect';
4358
updateHookTypesDev();
4288
- return mountEffect(create, deps);
4359
+ if (
4360
+ enableUseEffectCRUDOverload &&
4361
+ (typeof update === 'function' || typeof destroy === 'function')
4362
+ ) {
4363
+ return mountResourceEffect(
4364
+ create,
4365
+ createDeps,
4366
+ update,
4367
+ updateDeps,
4368
+ destroy,
4369
+ );
4370
+ } else {
4371
+ return mountEffect(create, createDeps);
4372
+ }
4373
},
4374
useImperativeHandle<T>(
4375
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
4551
return readContext(context);
4552
},
4553
useEffect(
4470
- create: () => (() => void) | void,
4471
- deps: Array<mixed> | void | null,
4554
+ create: (() => (() => void) | void) | (() => {...} | void | null),
4555
+ createDeps: Array<mixed> | void | null,
4556
+ update?: ((resource: {...} | void | null) => void) | void,
4557
+ updateDeps?: Array<mixed> | void | null,
4558
+ destroy?: ((resource: {...} | void | null) => void) | void,
4559
): void {
4560
currentHookNameInDev = 'useEffect';
4561
updateHookTypesDev();
4475
- return updateEffect(create, deps);
4562
+ if (
4563
+ enableUseEffectCRUDOverload &&
4564
+ (typeof update === 'function' || typeof destroy === 'function')
4565
+ ) {
4566
+ return updateResourceEffect(
4567
+ create,
4568
+ createDeps,
4569
+ update,
4570
+ updateDeps,
4571
+ destroy,
4572
+ );
4573
+ } else {
4574
+ return updateEffect(create, createDeps);
4575
+ }
4576
},
4577
useImperativeHandle<T>(
4578
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
4754
return readContext(context);
4755
},
4756
useEffect(
4657
- create: () => (() => void) | void,
4658
- deps: Array<mixed> | void | null,
4757
+ create: (() => (() => void) | void) | (() => {...} | void | null),
4758
+ createDeps: Array<mixed> | void | null,
4759
+ update?: ((resource: {...} | void | null) => void) | void,
4760
+ updateDeps?: Array<mixed> | void | null,
4761
+ destroy?: ((resource: {...} | void | null) => void) | void,
4762
): void {
4763
currentHookNameInDev = 'useEffect';
4764
updateHookTypesDev();
4662
- return updateEffect(create, deps);
4765
+ if (
4766
+ enableUseEffectCRUDOverload &&
4767
+ (typeof update === 'function' || typeof destroy === 'function')
4768
+ ) {
4769
+ return updateResourceEffect(
4770
+ create,
4771
+ createDeps,
4772
+ update,
4773
+ updateDeps,
4774
+ destroy,
4775
+ );
4776
+ } else {
4777
+ return updateEffect(create, createDeps);
4778
+ }
4779
},
4780
useImperativeHandle<T>(
4781
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
4963
return readContext(context);
4964
},
4965
useEffect(
4850
- create: () => (() => void) | void,
4851
- deps: Array<mixed> | void | null,
4966
+ create: (() => (() => void) | void) | (() => {...} | void | null),
4967
+ createDeps: Array<mixed> | void | null,
4968
+ update?: ((resource: {...} | void | null) => void) | void,
4969
+ updateDeps?: Array<mixed> | void | null,
4970
+ destroy?: ((resource: {...} | void | null) => void) | void,
4971
): void {
4972
currentHookNameInDev = 'useEffect';
4973
warnInvalidHookAccess();
4974
mountHookTypesDev();
4856
- return mountEffect(create, deps);
4975
+ if (
4976
+ enableUseEffectCRUDOverload &&
4977
+ (typeof update === 'function' || typeof destroy === 'function')
4978
+ ) {
4979
+ return mountResourceEffect(
4980
+ create,
4981
+ createDeps,
4982
+ update,
4983
+ updateDeps,
4984
+ destroy,
4985
+ );
4986
+ } else {
4987
+ return mountEffect(create, createDeps);
4988
+ }
4989
},
4990
useImperativeHandle<T>(
4991
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
5192
return readContext(context);
5193
},
5194
useEffect(
5063
- create: () => (() => void) | void,
5064
- deps: Array<mixed> | void | null,
5195
+ create: (() => (() => void) | void) | (() => {...} | void | null),
5196
+ createDeps: Array<mixed> | void | null,
5197
+ update?: ((resource: {...} | void | null) => void) | void,
5198
+ updateDeps?: Array<mixed> | void | null,
5199
+ destroy?: ((resource: {...} | void | null) => void) | void,
5200
): void {
5201
currentHookNameInDev = 'useEffect';
5202
warnInvalidHookAccess();
5203
updateHookTypesDev();
5069
- return updateEffect(create, deps);
5204
+ if (
5205
+ enableUseEffectCRUDOverload &&
5206
+ (typeof update === 'function' || typeof destroy === 'function')
5207
+ ) {
5208
+ return updateResourceEffect(
5209
+ create,
5210
+ createDeps,
5211
+ update,
5212
+ updateDeps,
5213
+ destroy,
5214
+ );
5215
+ } else {
5216
+ return updateEffect(create, createDeps);
5217
+ }
5218
},
5219
useImperativeHandle<T>(
5220
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
5421
return readContext(context);
5422
},
5423
useEffect(
5276
- create: () => (() => void) | void,
5277
- deps: Array<mixed> | void | null,
5424
+ create: (() => (() => void) | void) | (() => {...} | void | null),
5425
+ createDeps: Array<mixed> | void | null,
5426
+ update?: ((resource: {...} | void | null) => void) | void,
5427
+ updateDeps?: Array<mixed> | void | null,
5428
+ destroy?: ((resource: {...} | void | null) => void) | void,
5429
): void {
5430
currentHookNameInDev = 'useEffect';
5431
warnInvalidHookAccess();
5432
updateHookTypesDev();
5282
- return updateEffect(create, deps);
5433
+ if (
5434
+ enableUseEffectCRUDOverload &&
5435
+ (typeof update === 'function' || typeof destroy === 'function')
5436
+ ) {
5437
+ return updateResourceEffect(
5438
+ create,
5439
+ createDeps,
5440
+ update,
5441
+ updateDeps,
5442
+ destroy,
5443
+ );
5444
+ } else {
5445
+ return updateEffect(create, createDeps);
5446
+ }
5447
},
5448
useImperativeHandle<T>(
5449
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,