react - rename useImperativeMethods -> useImperativeHandle

This commit is contained in:
Sunil Pai
2019-01-14 21:25:15 +00:00
parent c747eccf6d
commit 2dc140b2bd
2 changed files with 6 additions and 6 deletions
+4 -4
View File
@@ -863,15 +863,15 @@ declare namespace React {
function useEffect(effect: EffectCallback, inputs?: InputIdentityList): void;
// NOTE: this does not accept strings, but this will have to be fixed by removing strings from type Ref<T>
/**
* `useImperativeMethods` customizes the instance value that is exposed to parent components when using
* `useImperativeHandle` customizes the instance value that is exposed to parent components when using
* `ref`. As always, imperative code using refs should be avoided in most cases.
*
* `useImperativeMethods` should be used with `React.forwardRef`.
* `useImperativeHandle` should be used with `React.forwardRef`.
*
* @version experimental
* @see https://reactjs.org/docs/hooks-reference.html#useimperativemethods
* @see https://reactjs.org/docs/hooks-reference.html#useimperativehandle
*/
function useImperativeMethods<T, R extends T>(ref: Ref<T>|undefined, init: () => R, inputs?: InputIdentityList): void;
function useImperativeHandle<T, R extends T>(ref: Ref<T>|undefined, init: () => R, inputs?: InputIdentityList): void;
// I made 'inputs' required here and in useMemo as there's no point to memoizing without the memoization key
// useCallback(X) is identical to just using X, useMemo(() => Y) is identical to just using Y.
/**
+2 -2
View File
@@ -21,7 +21,7 @@ export const FancyButton = React.forwardRef((props: FancyButtonProps, ref: React
const buttonRef = React.useRef<HTMLButtonElement | null>(null);
const [count, setCount] = React.useState(0);
React.useImperativeMethods(ref, () => ({
React.useImperativeHandle(ref, () => ({
fancyClick() {
buttonRef.current!; // $ExpectType HTMLButtonElement
},
@@ -91,7 +91,7 @@ function useEveryHook(ref: React.Ref<{ id: number }>|undefined): () => boolean {
const didLayout = React.useRef(false);
const id = React.useMemo(() => Math.random(), []);
React.useImperativeMethods(ref, () => ({ id }), [id]);
React.useImperativeHandle(ref, () => ({ id }), [id]);
// $ExpectError
React.useImperativeMethods(ref, () => ({}), [id]);