Skip to content

Commit

Permalink
compose: Add types to usePrevious (#31944)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarayourfriend committed May 21, 2021
1 parent 13a83e1 commit a9a0d47
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ _Parameters_

_Returns_

- `T|undefined`: The value from the previous render.
- `T | undefined`: The value from the previous render.

<a name="useReducedMotion" href="#useReducedMotion">#</a> **useReducedMotion**

Expand Down
4 changes: 2 additions & 2 deletions packages/compose/src/hooks/use-previous/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions packages/compose/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"src/hooks/use-debounce/**/*",
"src/hooks/use-instance-id/**/*",
"src/hooks/use-focus-return/**/*",
"src/hooks/use-previous/**/*",
"src/utils/**/*"
]
}

0 comments on commit a9a0d47

Please sign in to comment.