From a9a0d47330d1c77591bb38648f8c1ed7fb334df9 Mon Sep 17 00:00:00 2001 From: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com> Date: Fri, 21 May 2021 09:24:11 -0700 Subject: [PATCH] compose: Add types to `usePrevious` (#31944) --- packages/compose/README.md | 2 +- packages/compose/src/hooks/use-previous/index.js | 4 ++-- packages/compose/tsconfig.json | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/compose/README.md b/packages/compose/README.md index f72dfb4ce9e810..1a46e8fb19bf48 100644 --- a/packages/compose/README.md +++ b/packages/compose/README.md @@ -367,7 +367,7 @@ _Parameters_ _Returns_ -- `T|undefined`: The value from the previous render. +- `T | undefined`: The value from the previous render. # **useReducedMotion** diff --git a/packages/compose/src/hooks/use-previous/index.js b/packages/compose/src/hooks/use-previous/index.js index 035a272b06953c..c50e392a43226a 100644 --- a/packages/compose/src/hooks/use-previous/index.js +++ b/packages/compose/src/hooks/use-previous/index.js @@ -11,14 +11,14 @@ import { useEffect, useRef } from '@wordpress/element'; * * @param {T} value The value to track. * - * @return {T|undefined} The value from the previous render. + * @return {T | undefined} The value from the previous render. */ export default function usePrevious( value ) { // Disable reason: without an explicit type detail, the type of ref will be // inferred based on the initial useRef argument, which is undefined. // https://github.com/WordPress/gutenberg/pull/22597#issuecomment-633588366 /* eslint-disable jsdoc/no-undefined-types */ - const ref = useRef( /** @type {T|undefined} */ ( undefined ) ); + const ref = useRef( /** @type {T | undefined} */ ( undefined ) ); /* eslint-enable jsdoc/no-undefined-types */ // Store current value in ref. diff --git a/packages/compose/tsconfig.json b/packages/compose/tsconfig.json index 9544096d8ff048..0b134e049ff11a 100644 --- a/packages/compose/tsconfig.json +++ b/packages/compose/tsconfig.json @@ -19,6 +19,7 @@ "src/hooks/use-debounce/**/*", "src/hooks/use-instance-id/**/*", "src/hooks/use-focus-return/**/*", + "src/hooks/use-previous/**/*", "src/utils/**/*" ] }