Skip to content

Commit 2d97961

Browse files
committed
Rename UseEvent too
1 parent a1466f0 commit 2d97961

16 files changed

+55
-52
lines changed

packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ export default {
226226
if (name === 'useRef' && id.type === 'Identifier') {
227227
// useRef() return value is stable.
228228
return true;
229-
} else if (isUseEventIdentifier(callee) && id.type === 'Identifier') {
229+
} else if (
230+
isUseEffectEventIdentifier(callee) &&
231+
id.type === 'Identifier'
232+
) {
230233
for (const ref of resolved.references) {
231234
if (ref !== id) {
232235
useEffectEventVariables.add(ref.identifier);
@@ -1851,7 +1854,7 @@ function isAncestorNodeOf(a, b) {
18511854
return a.range[0] <= b.range[0] && a.range[1] >= b.range[1];
18521855
}
18531856

1854-
function isUseEventIdentifier(node) {
1857+
function isUseEffectEventIdentifier(node) {
18551858
if (__EXPERIMENTAL__) {
18561859
return node.type === 'Identifier' && node.name === 'useEffectEvent';
18571860
}

packages/eslint-plugin-react-hooks/src/RulesOfHooks.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function isInsideComponentOrHook(node) {
103103
return false;
104104
}
105105

106-
function isUseEventIdentifier(node) {
106+
function isUseEffectEventIdentifier(node) {
107107
if (__EXPERIMENTAL__) {
108108
return node.type === 'Identifier' && node.name === 'useEffectEvent';
109109
}
@@ -135,15 +135,15 @@ export default {
135135
// For a given scope, iterate through the references and add all useEffectEvent definitions. We can
136136
// do this in non-Program nodes because we can rely on the assumption that useEffectEvent functions
137137
// can only be declared within a component or hook at its top level.
138-
function recordAllUseEventFunctions(scope) {
138+
function recordAllUseEffectEventFunctions(scope) {
139139
for (const reference of scope.references) {
140140
const parent = reference.identifier.parent;
141141
if (
142142
parent.type === 'VariableDeclarator' &&
143143
parent.init &&
144144
parent.init.type === 'CallExpression' &&
145145
parent.init.callee &&
146-
isUseEventIdentifier(parent.init.callee)
146+
isUseEffectEventIdentifier(parent.init.callee)
147147
) {
148148
for (const ref of reference.resolved.references) {
149149
if (ref !== reference) {
@@ -576,7 +576,7 @@ export default {
576576
if (
577577
node.callee.type === 'Identifier' &&
578578
(node.callee.name === 'useEffect' ||
579-
isUseEventIdentifier(node.callee)) &&
579+
isUseEffectEventIdentifier(node.callee)) &&
580580
node.arguments.length > 0
581581
) {
582582
// Denote that we have traversed into a useEffect call, and stash the CallExpr for
@@ -613,14 +613,14 @@ export default {
613613
FunctionDeclaration(node) {
614614
// function MyComponent() { const onClick = useEffectEvent(...) }
615615
if (isInsideComponentOrHook(node)) {
616-
recordAllUseEventFunctions(context.getScope());
616+
recordAllUseEffectEventFunctions(context.getScope());
617617
}
618618
},
619619

620620
ArrowFunctionExpression(node) {
621621
// const MyComponent = () => { const onClick = useEffectEvent(...) }
622622
if (isInsideComponentOrHook(node)) {
623-
recordAllUseEventFunctions(context.getScope());
623+
recordAllUseEffectEventFunctions(context.getScope());
624624
}
625625
},
626626
};

packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5460,7 +5460,7 @@ describe('ReactDOMFizzServer', () => {
54605460
});
54615461

54625462
describe('useEffectEvent', () => {
5463-
// @gate enableUseEventHook
5463+
// @gate enableUseEffectEventHook
54645464
it('can server render a component with useEffectEvent', async () => {
54655465
const ref = React.createRef();
54665466
function App() {
@@ -5491,7 +5491,7 @@ describe('ReactDOMFizzServer', () => {
54915491
expect(getVisibleChildren(container)).toEqual(<button>1</button>);
54925492
});
54935493

5494-
// @gate enableUseEventHook
5494+
// @gate enableUseEffectEventHook
54955495
it('throws if useEffectEvent is called during a server render', async () => {
54965496
const logs = [];
54975497
function App() {
@@ -5523,7 +5523,7 @@ describe('ReactDOMFizzServer', () => {
55235523
expect(reportedServerErrors).toEqual([caughtError]);
55245524
});
55255525

5526-
// @gate enableUseEventHook
5526+
// @gate enableUseEffectEventHook
55275527
it('does not guarantee useEffectEvent return values during server rendering are distinct', async () => {
55285528
function App() {
55295529
const onClick1 = React.experimental_useEffectEvent(() => {});

packages/react-reconciler/src/ReactFiberCommitWork.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import {
5050
enableUpdaterTracking,
5151
enableCache,
5252
enableTransitionTracing,
53-
enableUseEventHook,
53+
enableUseEffectEventHook,
5454
enableFloat,
5555
enableLegacyHidden,
5656
enableHostSingletons,
@@ -454,9 +454,9 @@ function commitBeforeMutationEffectsOnFiber(finishedWork: Fiber) {
454454

455455
switch (finishedWork.tag) {
456456
case FunctionComponent: {
457-
if (enableUseEventHook) {
457+
if (enableUseEffectEventHook) {
458458
if ((flags & Update) !== NoFlags) {
459-
commitUseEventMount(finishedWork);
459+
commitUseEffectEventMount(finishedWork);
460460
}
461461
}
462462
break;
@@ -706,7 +706,7 @@ function commitHookEffectListMount(flags: HookFlags, finishedWork: Fiber) {
706706
}
707707
}
708708

709-
function commitUseEventMount(finishedWork: Fiber) {
709+
function commitUseEffectEventMount(finishedWork: Fiber) {
710710
const updateQueue: FunctionComponentUpdateQueue | null = (finishedWork.updateQueue: any);
711711
const eventPayloads = updateQueue !== null ? updateQueue.events : null;
712712
if (eventPayloads !== null) {

packages/react-reconciler/src/ReactFiberHooks.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
enableTransitionTracing,
3939
enableUseHook,
4040
enableUseMemoCacheHook,
41-
enableUseEventHook,
41+
enableUseEffectEventHook,
4242
enableLegacyCache,
4343
debugRenderPhaseSideEffectsForStrictMode,
4444
} from 'shared/ReactFeatureFlags';
@@ -2780,7 +2780,7 @@ if (enableUseHook) {
27802780
if (enableUseMemoCacheHook) {
27812781
(ContextOnlyDispatcher: Dispatcher).useMemoCache = throwInvalidHookError;
27822782
}
2783-
if (enableUseEventHook) {
2783+
if (enableUseEffectEventHook) {
27842784
(ContextOnlyDispatcher: Dispatcher).useEffectEvent = throwInvalidHookError;
27852785
}
27862786

@@ -2814,7 +2814,7 @@ if (enableUseHook) {
28142814
if (enableUseMemoCacheHook) {
28152815
(HooksDispatcherOnMount: Dispatcher).useMemoCache = useMemoCache;
28162816
}
2817-
if (enableUseEventHook) {
2817+
if (enableUseEffectEventHook) {
28182818
(HooksDispatcherOnMount: Dispatcher).useEffectEvent = mountEvent;
28192819
}
28202820
const HooksDispatcherOnUpdate: Dispatcher = {
@@ -2846,7 +2846,7 @@ if (enableUseMemoCacheHook) {
28462846
if (enableUseHook) {
28472847
(HooksDispatcherOnUpdate: Dispatcher).use = use;
28482848
}
2849-
if (enableUseEventHook) {
2849+
if (enableUseEffectEventHook) {
28502850
(HooksDispatcherOnUpdate: Dispatcher).useEffectEvent = updateEvent;
28512851
}
28522852

@@ -2879,7 +2879,7 @@ if (enableUseHook) {
28792879
if (enableUseMemoCacheHook) {
28802880
(HooksDispatcherOnRerender: Dispatcher).useMemoCache = useMemoCache;
28812881
}
2882-
if (enableUseEventHook) {
2882+
if (enableUseEffectEventHook) {
28832883
(HooksDispatcherOnRerender: Dispatcher).useEffectEvent = updateEvent;
28842884
}
28852885

@@ -3059,7 +3059,7 @@ if (__DEV__) {
30593059
if (enableUseMemoCacheHook) {
30603060
(HooksDispatcherOnMountInDEV: Dispatcher).useMemoCache = useMemoCache;
30613061
}
3062-
if (enableUseEventHook) {
3062+
if (enableUseEffectEventHook) {
30633063
(HooksDispatcherOnMountInDEV: Dispatcher).useEffectEvent = function useEffectEvent<
30643064
Args,
30653065
Return,
@@ -3214,7 +3214,7 @@ if (__DEV__) {
32143214
if (enableUseMemoCacheHook) {
32153215
(HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).useMemoCache = useMemoCache;
32163216
}
3217-
if (enableUseEventHook) {
3217+
if (enableUseEffectEventHook) {
32183218
(HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).useEffectEvent = function useEffectEvent<
32193219
Args,
32203220
Return,
@@ -3369,7 +3369,7 @@ if (__DEV__) {
33693369
if (enableUseMemoCacheHook) {
33703370
(HooksDispatcherOnUpdateInDEV: Dispatcher).useMemoCache = useMemoCache;
33713371
}
3372-
if (enableUseEventHook) {
3372+
if (enableUseEffectEventHook) {
33733373
(HooksDispatcherOnUpdateInDEV: Dispatcher).useEffectEvent = function useEffectEvent<
33743374
Args,
33753375
Return,
@@ -3525,7 +3525,7 @@ if (__DEV__) {
35253525
if (enableUseMemoCacheHook) {
35263526
(HooksDispatcherOnRerenderInDEV: Dispatcher).useMemoCache = useMemoCache;
35273527
}
3528-
if (enableUseEventHook) {
3528+
if (enableUseEffectEventHook) {
35293529
(HooksDispatcherOnRerenderInDEV: Dispatcher).useEffectEvent = function useEffectEvent<
35303530
Args,
35313531
Return,
@@ -3707,7 +3707,7 @@ if (__DEV__) {
37073707
return useMemoCache(size);
37083708
};
37093709
}
3710-
if (enableUseEventHook) {
3710+
if (enableUseEffectEventHook) {
37113711
(InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher).useEffectEvent = function useEffectEvent<
37123712
Args,
37133713
Return,
@@ -3890,7 +3890,7 @@ if (__DEV__) {
38903890
return useMemoCache(size);
38913891
};
38923892
}
3893-
if (enableUseEventHook) {
3893+
if (enableUseEffectEventHook) {
38943894
(InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher).useEffectEvent = function useEffectEvent<
38953895
Args,
38963896
Return,
@@ -4074,7 +4074,7 @@ if (__DEV__) {
40744074
return useMemoCache(size);
40754075
};
40764076
}
4077-
if (enableUseEventHook) {
4077+
if (enableUseEffectEventHook) {
40784078
(InvalidNestedHooksDispatcherOnRerenderInDEV: Dispatcher).useEffectEvent = function useEffectEvent<
40794079
Args,
40804080
Return,

packages/react-reconciler/src/__tests__/useEffectEvent-test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('useEffectEvent', () => {
5151
return <span prop={props.text} />;
5252
}
5353

54-
// @gate enableUseEventHook
54+
// @gate enableUseEffectEventHook
5555
it('memoizes basic case correctly', () => {
5656
class IncrementButton extends React.PureComponent {
5757
increment = () => {
@@ -117,7 +117,7 @@ describe('useEffectEvent', () => {
117117
]);
118118
});
119119

120-
// @gate enableUseEventHook
120+
// @gate enableUseEffectEventHook
121121
it('can be defined more than once', () => {
122122
class IncrementButton extends React.PureComponent {
123123
increment = () => {
@@ -173,7 +173,7 @@ describe('useEffectEvent', () => {
173173
]);
174174
});
175175

176-
// @gate enableUseEventHook
176+
// @gate enableUseEffectEventHook
177177
it('does not preserve `this` in event functions', () => {
178178
class GreetButton extends React.PureComponent {
179179
greet = () => {
@@ -222,7 +222,7 @@ describe('useEffectEvent', () => {
222222
]);
223223
});
224224

225-
// @gate enableUseEventHook
225+
// @gate enableUseEffectEventHook
226226
it('throws when called in render', () => {
227227
class IncrementButton extends React.PureComponent {
228228
increment = () => {
@@ -259,7 +259,7 @@ describe('useEffectEvent', () => {
259259
expect(Scheduler).toHaveYielded(['Count: 0', 'Count: 0']);
260260
});
261261

262-
// @gate enableUseEventHook
262+
// @gate enableUseEffectEventHook
263263
it("useLayoutEffect shouldn't re-fire when event handlers change", () => {
264264
class IncrementButton extends React.PureComponent {
265265
increment = () => {
@@ -349,7 +349,7 @@ describe('useEffectEvent', () => {
349349
]);
350350
});
351351

352-
// @gate enableUseEventHook
352+
// @gate enableUseEffectEventHook
353353
it("useEffect shouldn't re-fire when event handlers change", () => {
354354
class IncrementButton extends React.PureComponent {
355355
increment = () => {
@@ -438,7 +438,7 @@ describe('useEffectEvent', () => {
438438
]);
439439
});
440440

441-
// @gate enableUseEventHook
441+
// @gate enableUseEffectEventHook
442442
it('is stable in a custom hook', () => {
443443
class IncrementButton extends React.PureComponent {
444444
increment = () => {
@@ -533,7 +533,7 @@ describe('useEffectEvent', () => {
533533
]);
534534
});
535535

536-
// @gate enableUseEventHook
536+
// @gate enableUseEffectEventHook
537537
it('is mutated before all other effects', () => {
538538
function Counter({value}) {
539539
useInsertionEffect(() => {
@@ -557,7 +557,7 @@ describe('useEffectEvent', () => {
557557
expect(Scheduler).toHaveYielded(['Effect value: 2', 'Event value: 2']);
558558
});
559559

560-
// @gate enableUseEventHook
560+
// @gate enableUseEffectEventHook
561561
it("doesn't provide a stable identity", () => {
562562
function Counter({shouldRender, value}) {
563563
const onClick = useEffectEvent(() => {
@@ -596,7 +596,7 @@ describe('useEffectEvent', () => {
596596
]);
597597
});
598598

599-
// @gate enableUseEventHook
599+
// @gate enableUseEffectEventHook
600600
it('event handlers always see the latest committed value', async () => {
601601
let committedEventHandler = null;
602602

@@ -646,7 +646,7 @@ describe('useEffectEvent', () => {
646646
expect(committedEventHandler()).toBe('Value seen by useEffectEvent: 2');
647647
});
648648

649-
// @gate enableUseEventHook
649+
// @gate enableUseEffectEventHook
650650
it('integration: implements docs chat room example', () => {
651651
function createConnection() {
652652
let connectedCallback;
@@ -735,7 +735,7 @@ describe('useEffectEvent', () => {
735735
expect(Scheduler).toHaveYielded(['Connected! theme: dark']);
736736
});
737737

738-
// @gate enableUseEventHook
738+
// @gate enableUseEffectEventHook
739739
it('integration: implements the docs logVisit example', () => {
740740
class AddToCartButton extends React.PureComponent {
741741
addToCart = () => {

packages/react-server/src/ReactFizzHooks.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {makeId} from './ReactServerFormatConfig';
3232
import {
3333
enableCache,
3434
enableUseHook,
35-
enableUseEventHook,
35+
enableUseEffectEventHook,
3636
enableUseMemoCacheHook,
3737
} from 'shared/ReactFeatureFlags';
3838
import is from 'shared/objectIs';
@@ -507,7 +507,7 @@ export function useCallback<T>(
507507
return useMemo(() => callback, deps);
508508
}
509509

510-
function throwOnUseEventCall() {
510+
function throwOnUseEffectEventCall() {
511511
throw new Error(
512512
"A function wrapped in useEffectEvent can't be called during rendering.",
513513
);
@@ -517,7 +517,7 @@ export function useEffectEvent<Args, Return, F: (...Array<Args>) => Return>(
517517
callback: F,
518518
): F {
519519
// $FlowIgnore[incompatible-return]
520-
return throwOnUseEventCall;
520+
return throwOnUseEffectEventCall;
521521
}
522522

523523
// TODO Decide on how to implement this hook for server rendering.
@@ -651,7 +651,7 @@ export const HooksDispatcher: Dispatcher = {
651651
if (enableCache) {
652652
HooksDispatcher.useCacheRefresh = useCacheRefresh;
653653
}
654-
if (enableUseEventHook) {
654+
if (enableUseEffectEventHook) {
655655
HooksDispatcher.useEffectEvent = useEffectEvent;
656656
}
657657
if (enableUseMemoCacheHook) {

packages/shared/ReactFeatureFlags.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export const enableUseHook = true;
121121
// auto-memoization.
122122
export const enableUseMemoCacheHook = __EXPERIMENTAL__;
123123

124-
export const enableUseEventHook = __EXPERIMENTAL__;
124+
export const enableUseEffectEventHook = __EXPERIMENTAL__;
125125

126126
// Test in www before enabling in open source.
127127
// Enables DOM-server to stream its instruction set as data-attributes

0 commit comments

Comments
 (0)