Skip to content

Commit 6b30524

Browse files
committed
Rename experimental useEvent to useEffectEvent (#25881)
We originally had grand plans for using this Event concept for more but now it's only meant to be used in combination with effects. It's an Event in the FRP terms, that is triggered from an Effect. Technically it can also be from another function that itself is triggered from an existing side-effect but that's kind of an advanced case. The canonical case is an effect that triggers an event: ```js const onHappened = useEffectEvent(() => ...); useEffect(() => { onHappened(); }, []); ``` DiffTrain build for [84a0a17](84a0a17) [View git log for this commit](https://github.com/facebook/react/commits/84a0a171ea0ecd25e287bd3d3dd30e932beb4677)
1 parent 385f204 commit 6b30524

31 files changed

+249
-225
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4dda96a4071d2cc4bbcc444438cfacee991f07e2
1+
84a0a171ea0ecd25e287bd3d3dd30e932beb4677
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4dda96a4071d2cc4bbcc444438cfacee991f07e2
1+
84a0a171ea0ecd25e287bd3d3dd30e932beb4677

compiled/facebook-www/React-dev.classic.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (
2727
}
2828
"use strict";
2929

30-
var ReactVersion = "18.3.0-www-classic-4dda96a40-20221213";
30+
var ReactVersion = "18.3.0-www-classic-84a0a171e-20221214";
3131

3232
// ATTENTION
3333
// When adding new symbols to this file,
@@ -2054,10 +2054,10 @@ function useMemoCache(size) {
20542054

20552055
return dispatcher.useMemoCache(size);
20562056
}
2057-
function useEvent(callback) {
2057+
function useEffectEvent(callback) {
20582058
var dispatcher = resolveDispatcher(); // $FlowFixMe This is unstable, thus optional
20592059

2060-
return dispatcher.useEvent(callback);
2060+
return dispatcher.useEffectEvent(callback);
20612061
}
20622062

20632063
// Helpers to patch console.logs to avoid logging during side-effect free
@@ -4197,7 +4197,7 @@ exports.createFactory = createFactory;
41974197
exports.createMutableSource = createMutableSource;
41984198
exports.createRef = createRef;
41994199
exports.createServerContext = createServerContext;
4200-
exports.experimental_useEvent = useEvent;
4200+
exports.experimental_useEffectEvent = useEffectEvent;
42014201
exports.forwardRef = forwardRef;
42024202
exports.isValidElement = isValidElement;
42034203
exports.jsx = jsx;

compiled/facebook-www/React-dev.modern.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (
2727
}
2828
"use strict";
2929

30-
var ReactVersion = "18.3.0-www-modern-4dda96a40-20221213";
30+
var ReactVersion = "18.3.0-www-modern-84a0a171e-20221214";
3131

3232
// ATTENTION
3333
// When adding new symbols to this file,
@@ -2054,10 +2054,10 @@ function useMemoCache(size) {
20542054

20552055
return dispatcher.useMemoCache(size);
20562056
}
2057-
function useEvent(callback) {
2057+
function useEffectEvent(callback) {
20582058
var dispatcher = resolveDispatcher(); // $FlowFixMe This is unstable, thus optional
20592059

2060-
return dispatcher.useEvent(callback);
2060+
return dispatcher.useEffectEvent(callback);
20612061
}
20622062

20632063
// Helpers to patch console.logs to avoid logging during side-effect free
@@ -4161,7 +4161,7 @@ exports.createElement = createElement$1;
41614161
exports.createMutableSource = createMutableSource;
41624162
exports.createRef = createRef;
41634163
exports.createServerContext = createServerContext;
4164-
exports.experimental_useEvent = useEvent;
4164+
exports.experimental_useEffectEvent = useEffectEvent;
41654165
exports.forwardRef = forwardRef;
41664166
exports.isValidElement = isValidElement;
41674167
exports.jsx = jsx;

compiled/facebook-www/React-prod.classic.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,8 @@ exports.createServerContext = function(globalName, defaultValue) {
530530
throw Error("ServerContext: " + globalName + " already defined");
531531
return context$1;
532532
};
533-
exports.experimental_useEvent = function(callback) {
534-
return ReactCurrentDispatcher.current.useEvent(callback);
533+
exports.experimental_useEffectEvent = function(callback) {
534+
return ReactCurrentDispatcher.current.useEffectEvent(callback);
535535
};
536536
exports.forwardRef = function(render) {
537537
return { $$typeof: REACT_FORWARD_REF_TYPE, render: render };
@@ -643,4 +643,4 @@ exports.useSyncExternalStore = function(
643643
);
644644
};
645645
exports.useTransition = useTransition;
646-
exports.version = "18.3.0-www-classic-4dda96a40-20221213";
646+
exports.version = "18.3.0-www-classic-84a0a171e-20221214";

compiled/facebook-www/React-prod.modern.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,8 @@ exports.createServerContext = function(globalName, defaultValue) {
523523
throw Error("ServerContext: " + globalName + " already defined");
524524
return context$1;
525525
};
526-
exports.experimental_useEvent = function(callback) {
527-
return ReactCurrentDispatcher.current.useEvent(callback);
526+
exports.experimental_useEffectEvent = function(callback) {
527+
return ReactCurrentDispatcher.current.useEffectEvent(callback);
528528
};
529529
exports.forwardRef = function(render) {
530530
return { $$typeof: REACT_FORWARD_REF_TYPE, render: render };
@@ -635,4 +635,4 @@ exports.useSyncExternalStore = function(
635635
);
636636
};
637637
exports.useTransition = useTransition;
638-
exports.version = "18.3.0-www-modern-4dda96a40-20221213";
638+
exports.version = "18.3.0-www-modern-84a0a171e-20221214";

compiled/facebook-www/React-profiling.classic.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ exports.createServerContext = function(globalName, defaultValue) {
541541
throw Error("ServerContext: " + globalName + " already defined");
542542
return context$1;
543543
};
544-
exports.experimental_useEvent = function(callback) {
545-
return ReactCurrentDispatcher.current.useEvent(callback);
544+
exports.experimental_useEffectEvent = function(callback) {
545+
return ReactCurrentDispatcher.current.useEffectEvent(callback);
546546
};
547547
exports.forwardRef = function(render) {
548548
return { $$typeof: REACT_FORWARD_REF_TYPE, render: render };
@@ -654,7 +654,7 @@ exports.useSyncExternalStore = function(
654654
);
655655
};
656656
exports.useTransition = useTransition;
657-
exports.version = "18.3.0-www-classic-4dda96a40-20221213";
657+
exports.version = "18.3.0-www-classic-84a0a171e-20221214";
658658

659659
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
660660
if (

compiled/facebook-www/React-profiling.modern.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,8 @@ exports.createServerContext = function(globalName, defaultValue) {
534534
throw Error("ServerContext: " + globalName + " already defined");
535535
return context$1;
536536
};
537-
exports.experimental_useEvent = function(callback) {
538-
return ReactCurrentDispatcher.current.useEvent(callback);
537+
exports.experimental_useEffectEvent = function(callback) {
538+
return ReactCurrentDispatcher.current.useEffectEvent(callback);
539539
};
540540
exports.forwardRef = function(render) {
541541
return { $$typeof: REACT_FORWARD_REF_TYPE, render: render };
@@ -646,7 +646,7 @@ exports.useSyncExternalStore = function(
646646
);
647647
};
648648
exports.useTransition = useTransition;
649-
exports.version = "18.3.0-www-modern-4dda96a40-20221213";
649+
exports.version = "18.3.0-www-modern-84a0a171e-20221214";
650650

651651
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
652652
if (

compiled/facebook-www/ReactART-dev.classic.js

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
6969
return self;
7070
}
7171

72-
var ReactVersion = "18.3.0-www-classic-4dda96a40-20221213";
72+
var ReactVersion = "18.3.0-www-classic-84a0a171e-20221214";
7373

7474
var LegacyRoot = 0;
7575
var ConcurrentRoot = 1;
@@ -8899,7 +8899,7 @@ function updateEffect(create, deps) {
88998899
updateEffectImpl(Passive, Passive$1, create, deps);
89008900
}
89018901

8902-
function useEventImpl(payload) {
8902+
function useEffectEventImpl(payload) {
89038903
currentlyRenderingFiber.flags |= Update;
89048904
var componentUpdateQueue = currentlyRenderingFiber.updateQueue;
89058905

@@ -8928,7 +8928,7 @@ function mountEvent(callback) {
89288928
return function eventFn() {
89298929
if (isInvalidExecutionContextForEventFunction()) {
89308930
throw new Error(
8931-
"A function wrapped in useEvent can't be called during rendering."
8931+
"A function wrapped in useEffectEvent can't be called during rendering."
89328932
);
89338933
}
89348934

@@ -8939,15 +8939,15 @@ function mountEvent(callback) {
89398939
function updateEvent(callback) {
89408940
var hook = updateWorkInProgressHook();
89418941
var ref = hook.memoizedState;
8942-
useEventImpl({
8942+
useEffectEventImpl({
89438943
ref: ref,
89448944
nextImpl: callback
89458945
}); // $FlowIgnore[incompatible-return]
89468946

89478947
return function eventFn() {
89488948
if (isInvalidExecutionContextForEventFunction()) {
89498949
throw new Error(
8950-
"A function wrapped in useEvent can't be called during rendering."
8950+
"A function wrapped in useEffectEvent can't be called during rendering."
89518951
);
89528952
}
89538953

@@ -9570,7 +9570,7 @@ var ContextOnlyDispatcher = {
95709570
}
95719571

95729572
{
9573-
ContextOnlyDispatcher.useEvent = throwInvalidHookError;
9573+
ContextOnlyDispatcher.useEffectEvent = throwInvalidHookError;
95749574
}
95759575

95769576
var HooksDispatcherOnMountInDEV = null;
@@ -9730,8 +9730,10 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
97309730
}
97319731

97329732
{
9733-
HooksDispatcherOnMountInDEV.useEvent = function useEvent(callback) {
9734-
currentHookNameInDev = "useEvent";
9733+
HooksDispatcherOnMountInDEV.useEffectEvent = function useEffectEvent(
9734+
callback
9735+
) {
9736+
currentHookNameInDev = "useEffectEvent";
97359737
mountHookTypesDev();
97369738
return mountEvent(callback);
97379739
};
@@ -9861,10 +9863,10 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
98619863
}
98629864

98639865
{
9864-
HooksDispatcherOnMountWithHookTypesInDEV.useEvent = function useEvent(
9866+
HooksDispatcherOnMountWithHookTypesInDEV.useEffectEvent = function useEffectEvent(
98659867
callback
98669868
) {
9867-
currentHookNameInDev = "useEvent";
9869+
currentHookNameInDev = "useEffectEvent";
98689870
updateHookTypesDev();
98699871
return mountEvent(callback);
98709872
};
@@ -9994,8 +9996,10 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
99949996
}
99959997

99969998
{
9997-
HooksDispatcherOnUpdateInDEV.useEvent = function useEvent(callback) {
9998-
currentHookNameInDev = "useEvent";
9999+
HooksDispatcherOnUpdateInDEV.useEffectEvent = function useEffectEvent(
10000+
callback
10001+
) {
10002+
currentHookNameInDev = "useEffectEvent";
999910003
updateHookTypesDev();
1000010004
return updateEvent(callback);
1000110005
};
@@ -10125,8 +10129,10 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
1012510129
}
1012610130

1012710131
{
10128-
HooksDispatcherOnRerenderInDEV.useEvent = function useEvent(callback) {
10129-
currentHookNameInDev = "useEvent";
10132+
HooksDispatcherOnRerenderInDEV.useEffectEvent = function useEffectEvent(
10133+
callback
10134+
) {
10135+
currentHookNameInDev = "useEffectEvent";
1013010136
updateHookTypesDev();
1013110137
return updateEvent(callback);
1013210138
};
@@ -10279,10 +10285,10 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
1027910285
}
1028010286

1028110287
{
10282-
InvalidNestedHooksDispatcherOnMountInDEV.useEvent = function useEvent(
10288+
InvalidNestedHooksDispatcherOnMountInDEV.useEffectEvent = function useEffectEvent(
1028310289
callback
1028410290
) {
10285-
currentHookNameInDev = "useEvent";
10291+
currentHookNameInDev = "useEffectEvent";
1028610292
warnInvalidHookAccess();
1028710293
mountHookTypesDev();
1028810294
return mountEvent(callback);
@@ -10436,10 +10442,10 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
1043610442
}
1043710443

1043810444
{
10439-
InvalidNestedHooksDispatcherOnUpdateInDEV.useEvent = function useEvent(
10445+
InvalidNestedHooksDispatcherOnUpdateInDEV.useEffectEvent = function useEffectEvent(
1044010446
callback
1044110447
) {
10442-
currentHookNameInDev = "useEvent";
10448+
currentHookNameInDev = "useEffectEvent";
1044310449
warnInvalidHookAccess();
1044410450
updateHookTypesDev();
1044510451
return updateEvent(callback);
@@ -10593,10 +10599,10 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
1059310599
}
1059410600

1059510601
{
10596-
InvalidNestedHooksDispatcherOnRerenderInDEV.useEvent = function useEvent(
10602+
InvalidNestedHooksDispatcherOnRerenderInDEV.useEffectEvent = function useEffectEvent(
1059710603
callback
1059810604
) {
10599-
currentHookNameInDev = "useEvent";
10605+
currentHookNameInDev = "useEffectEvent";
1060010606
warnInvalidHookAccess();
1060110607
updateHookTypesDev();
1060210608
return updateEvent(callback);
@@ -18965,7 +18971,7 @@ function commitBeforeMutationEffectsOnFiber(finishedWork) {
1896518971
case FunctionComponent: {
1896618972
{
1896718973
if ((flags & Update) !== NoFlags) {
18968-
commitUseEventMount(finishedWork);
18974+
commitUseEffectEventMount(finishedWork);
1896918975
}
1897018976
}
1897118977

@@ -19244,7 +19250,7 @@ function commitHookEffectListMount(flags, finishedWork) {
1924419250
}
1924519251
}
1924619252

19247-
function commitUseEventMount(finishedWork) {
19253+
function commitUseEffectEventMount(finishedWork) {
1924819254
var updateQueue = finishedWork.updateQueue;
1924919255
var eventPayloads = updateQueue !== null ? updateQueue.events : null;
1925019256

0 commit comments

Comments
 (0)