From 2dc140b2bdc72b252aa515e4d311a6c4e9cbcc93 Mon Sep 17 00:00:00 2001 From: Sunil Pai Date: Mon, 14 Jan 2019 21:25:15 +0000 Subject: [PATCH 1/2] react - rename useImperativeMethods -> useImperativeHandle --- types/react/index.d.ts | 8 ++++---- types/react/test/hooks.tsx | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/types/react/index.d.ts b/types/react/index.d.ts index 11d879b2ff..179f8bf73f 100644 --- a/types/react/index.d.ts +++ b/types/react/index.d.ts @@ -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 /** - * `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(ref: Ref|undefined, init: () => R, inputs?: InputIdentityList): void; + function useImperativeHandle(ref: Ref|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. /** diff --git a/types/react/test/hooks.tsx b/types/react/test/hooks.tsx index 5239d3b522..5cb0c1512c 100644 --- a/types/react/test/hooks.tsx +++ b/types/react/test/hooks.tsx @@ -21,7 +21,7 @@ export const FancyButton = React.forwardRef((props: FancyButtonProps, ref: React const buttonRef = React.useRef(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]); From 6f7766f0cf4cec7132a361002809abff75bfdd0b Mon Sep 17 00:00:00 2001 From: Sunil Pai Date: Mon, 14 Jan 2019 21:42:52 +0000 Subject: [PATCH 2/2] update version number --- types/react/index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/react/index.d.ts b/types/react/index.d.ts index 179f8bf73f..f2626e95b7 100644 --- a/types/react/index.d.ts +++ b/types/react/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for React 16.7 +// Type definitions for React 16.8 // Project: http://facebook.github.io/react/ // Definitions by: Asana // AssureSign @@ -20,6 +20,7 @@ // Frank Li // Jessica Franco // Paul Sherman +// Sunil Pai // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8