rename useImperativeMethods -> useImperativeHandle (#14565)
Sunil Pai committed
Jan 10, 2019 at 13:37 UTC
b4ad8e947150a1a0b486a388e2d4762d3eee51ee
9 files changed
+32
-32
packages/react-debug-tools/src/ReactDebugHooks.js
+4
-4
@@ -54,7 +54,7 @@ function getPrimitiveStackCache(): Map<string, Array<any>> {
54
Dispatcher.useRef(null);
55
Dispatcher.useLayoutEffect(() => {});
56
Dispatcher.useEffect(() => {});
57
- Dispatcher.useImperativeMethods(undefined, () => null);
57
+ Dispatcher.useImperativeHandle(undefined, () => null);
58
Dispatcher.useCallback(() => {});
59
Dispatcher.useMemo(() => null);
60
} finally {
@@ -159,7 +159,7 @@ function useEffect(
159
hookLog.push({primitive: 'Effect', stackError: new Error(), value: create});
160
}
161
162
-function useImperativeMethods<T>(
162
+function useImperativeHandle<T>(
163
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
164
create: () => T,
165
inputs: Array<mixed> | void | null,
@@ -174,7 +174,7 @@ function useImperativeMethods<T>(
174
instance = ref.current;
175
}
176
hookLog.push({
177
- primitive: 'ImperativeMethods',
177
+ primitive: 'ImperativeHandle',
178
stackError: new Error(),
179
value: instance,
180
});
@@ -205,7 +205,7 @@ const Dispatcher = {
205
useCallback,
206
useContext,
207
useEffect,
208
- useImperativeMethods,
208
+ useImperativeHandle,
209
useLayoutEffect,
210
useMemo,
211
useReducer,
packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.internal.js
+5
-5
@@ -82,7 +82,7 @@ describe('ReactHooksInspectionIntergration', () => {
82
React.useLayoutEffect(effect);
83
React.useEffect(effect);
84
85
- React.useImperativeMethods(
85
+ React.useImperativeHandle(
86
outsideRef,
87
() => {
88
// Return a function so that jest treats them as non-equal.
@@ -118,7 +118,7 @@ describe('ReactHooksInspectionIntergration', () => {
118
{name: 'Ref', value: 'c', subHooks: []},
119
{name: 'LayoutEffect', value: effect, subHooks: []},
120
{name: 'Effect', value: effect, subHooks: []},
121
- {name: 'ImperativeMethods', value: outsideRef.current, subHooks: []},
121
+ {name: 'ImperativeHandle', value: outsideRef.current, subHooks: []},
122
{name: 'Memo', value: 'ab', subHooks: []},
123
{name: 'Callback', value: updateStates, subHooks: []},
124
]);
@@ -134,7 +134,7 @@ describe('ReactHooksInspectionIntergration', () => {
134
{name: 'Ref', value: 'C', subHooks: []},
135
{name: 'LayoutEffect', value: effect, subHooks: []},
136
{name: 'Effect', value: effect, subHooks: []},
137
- {name: 'ImperativeMethods', value: outsideRef.current, subHooks: []},
137
+ {name: 'ImperativeHandle', value: outsideRef.current, subHooks: []},
138
{name: 'Memo', value: 'Ab', subHooks: []},
139
{name: 'Callback', value: updateStates, subHooks: []},
140
]);
@@ -165,7 +165,7 @@ describe('ReactHooksInspectionIntergration', () => {
165
it('should inspect forwardRef', () => {
166
let obj = function() {};
167
let Foo = React.forwardRef(function(props, ref) {
168
- React.useImperativeMethods(ref, () => obj);
168
+ React.useImperativeHandle(ref, () => obj);
169
return <div />;
170
});
171
let ref = React.createRef();
@@ -174,7 +174,7 @@ describe('ReactHooksInspectionIntergration', () => {
174
let childFiber = renderer.root.findByType(Foo)._currentFiber();
175
let tree = ReactDebugTools.inspectHooksOfFiber(childFiber);
176
expect(tree).toEqual([
177
- {name: 'ImperativeMethods', value: obj, subHooks: []},
177
+ {name: 'ImperativeHandle', value: obj, subHooks: []},
178
]);
179
});
180
packages/react-dom/src/__tests__/ReactDOMServerIntegrationHooks-test.internal.js
+4
-4
@@ -24,7 +24,7 @@ let useContext;
24
let useCallback;
25
let useMemo;
26
let useRef;
27
-let useImperativeMethods;
27
+let useImperativeHandle;
28
let useLayoutEffect;
29
let forwardRef;
30
let yieldedValues;
@@ -48,7 +48,7 @@ function initModules() {
48
useCallback = React.useCallback;
49
useMemo = React.useMemo;
50
useRef = React.useRef;
51
- useImperativeMethods = React.useImperativeMethods;
51
+ useImperativeHandle = React.useImperativeHandle;
52
useLayoutEffect = React.useLayoutEffect;
53
forwardRef = React.forwardRef;
54
@@ -529,10 +529,10 @@ describe('ReactDOMServerHooks', () => {
529
});
530
});
531
532
- describe('useImperativeMethods', () => {
532
+ describe('useImperativeHandle', () => {
533
it('should not be invoked on the server', async () => {
534
function Counter(props, ref) {
535
- useImperativeMethods(ref, () => {
535
+ useImperativeHandle(ref, () => {
536
throw new Error('should not be invoked');
537
});
538
return <Text text={props.label + ': ' + ref.current} />;
packages/react-dom/src/server/ReactPartialRendererHooks.js
+2
-2
@@ -347,8 +347,8 @@ export const Dispatcher = {
347
useLayoutEffect,
348
// Callbacks are passed as they are in the server environment.
349
useCallback: identity,
350
- // useImperativeMethods is not run in the server environment
351
- useImperativeMethods: noop,
350
+ // useImperativeHandle is not run in the server environment
351
+ useImperativeHandle: noop,
352
// Effects are not run in the server environment.
353
useEffect: noop,
354
};
packages/react-reconciler/src/ReactFiberDispatcher.js
+2
-2
@@ -12,7 +12,7 @@ import {
12
useCallback,
13
useContext,
14
useEffect,
15
- useImperativeMethods,
15
+ useImperativeHandle,
16
useLayoutEffect,
17
useMemo,
18
useReducer,
@@ -25,7 +25,7 @@ export const Dispatcher = {
25
useCallback,
26
useContext,
27
useEffect,
28
- useImperativeMethods,
28
+ useImperativeHandle,
29
useLayoutEffect,
30
useMemo,
31
useReducer,
packages/react-reconciler/src/ReactFiberHooks.js
+1
-1
@@ -557,7 +557,7 @@ function useEffectImpl(fiberEffectTag, hookEffectTag, create, inputs): void {
557
);
558
}
559
560
-export function useImperativeMethods<T>(
560
+export function useImperativeHandle<T>(
561
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
562
create: () => T,
563
inputs: Array<mixed> | void | null,
packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.internal.js
+10
-10
@@ -23,7 +23,7 @@ let useLayoutEffect;
23
let useCallback;
24
let useMemo;
25
let useRef;
26
-let useImperativeMethods;
26
+let useImperativeHandle;
27
let forwardRef;
28
let flushPassiveEffects;
29
let memo;
@@ -71,7 +71,7 @@ describe('ReactHooksWithNoopRenderer', () => {
71
useCallback = React.useCallback;
72
useMemo = React.useMemo;
73
useRef = React.useRef;
74
- useImperativeMethods = React.useImperativeMethods;
74
+ useImperativeHandle = React.useImperativeHandle;
75
forwardRef = React.forwardRef;
76
memo = React.memo;
77
});
@@ -88,7 +88,7 @@ describe('ReactHooksWithNoopRenderer', () => {
88
it('resumes after an interruption', () => {
89
function Counter(props, ref) {
90
const [count, updateCount] = useState(0);
91
- useImperativeMethods(ref, () => ({updateCount}));
91
+ useImperativeHandle(ref, () => ({updateCount}));
92
return <Text text={props.label + ': ' + count} />;
93
}
94
Counter = forwardRef(Counter);
@@ -172,7 +172,7 @@ describe('ReactHooksWithNoopRenderer', () => {
172
it('simple mount and update', () => {
173
function Counter(props, ref) {
174
const [count, updateCount] = useState(0);
175
- useImperativeMethods(ref, () => ({updateCount}));
175
+ useImperativeHandle(ref, () => ({updateCount}));
176
return <Text text={'Count: ' + count} />;
177
}
178
Counter = forwardRef(Counter);
@@ -196,7 +196,7 @@ describe('ReactHooksWithNoopRenderer', () => {
196
ReactNoop.yield('getInitialState');
197
return props.initialState;
198
});
199
- useImperativeMethods(ref, () => ({updateCount}));
199
+ useImperativeHandle(ref, () => ({updateCount}));
200
return <Text text={'Count: ' + count} />;
201
}
202
Counter = forwardRef(Counter);
@@ -214,7 +214,7 @@ describe('ReactHooksWithNoopRenderer', () => {
214
function Counter(props, ref) {
215
const [count, updateCount] = useState(0);
216
const [label, updateLabel] = useState('Count');
217
- useImperativeMethods(ref, () => ({updateCount, updateLabel}));
217
+ useImperativeHandle(ref, () => ({updateCount, updateLabel}));
218
return <Text text={label + ': ' + count} />;
219
}
220
Counter = forwardRef(Counter);
@@ -444,7 +444,7 @@ describe('ReactHooksWithNoopRenderer', () => {
444
function Counter({row: newRow}, ref) {
445
let [reducer, setReducer] = useState(() => reducerA);
446
let [count, dispatch] = useReducer(reducer, 0);
447
- useImperativeMethods(ref, () => ({dispatch}));
447
+ useImperativeHandle(ref, () => ({dispatch}));
448
if (count < 20) {
449
dispatch('increment');
450
// Swap reducers each time we increment
@@ -505,7 +505,7 @@ describe('ReactHooksWithNoopRenderer', () => {
505
506
function Counter(props, ref) {
507
const [count, dispatch] = useReducer(reducer, 0);
508
- useImperativeMethods(ref, () => ({dispatch}));
508
+ useImperativeHandle(ref, () => ({dispatch}));
509
return <Text text={'Count: ' + count} />;
510
}
511
Counter = forwardRef(Counter);
@@ -546,7 +546,7 @@ describe('ReactHooksWithNoopRenderer', () => {
546
547
function Counter(props, ref) {
548
const [count, dispatch] = useReducer(reducer, 0, initialAction);
549
- useImperativeMethods(ref, () => ({dispatch}));
549
+ useImperativeHandle(ref, () => ({dispatch}));
550
return <Text text={'Count: ' + count} />;
551
}
552
Counter = forwardRef(Counter);
@@ -576,7 +576,7 @@ describe('ReactHooksWithNoopRenderer', () => {
576
577
function Counter(props, ref) {
578
const [count, dispatch] = useReducer(reducer, 0);
579
- useImperativeMethods(ref, () => ({dispatch}));
579
+ useImperativeHandle(ref, () => ({dispatch}));
580
return <Text text={'Count: ' + count} />;
581
}
582
packages/react/src/React.js
+2
-2
@@ -32,7 +32,7 @@ import {
32
useCallback,
33
useContext,
34
useEffect,
35
- useImperativeMethods,
35
+ useImperativeHandle,
36
useLayoutEffect,
37
useMemo,
38
useReducer,
@@ -98,7 +98,7 @@ if (enableHooks) {
98
React.useCallback = useCallback;
99
React.useContext = useContext;
100
React.useEffect = useEffect;
101
- React.useImperativeMethods = useImperativeMethods;
101
+ React.useImperativeHandle = useImperativeHandle;
102
React.useLayoutEffect = useLayoutEffect;
103
React.useMemo = useMemo;
104
React.useReducer = useReducer;
packages/react/src/ReactHooks.js
+2
-2
@@ -102,11 +102,11 @@ export function useMemo(
102
return dispatcher.useMemo(create, inputs);
103
}
104
105
-export function useImperativeMethods<T>(
105
+export function useImperativeHandle<T>(
106
ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
107
create: () => T,
108
inputs: Array<mixed> | void | null,
109
): void {
110
const dispatcher = resolveDispatcher();
111
- return dispatcher.useImperativeMethods(ref, create, inputs);
111
+ return dispatcher.useImperativeHandle(ref, create, inputs);
112
}