Skip to content

Commit

Permalink
compose: Add types to usePrevious
Browse files Browse the repository at this point in the history
  • Loading branch information
sarayourfriend committed May 19, 2021
1 parent 8dad8c8 commit 409eef1
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 @@ -332,7 +332,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 @@ -17,6 +17,7 @@
"src/hooks/use-async-list/**/*",
"src/hooks/use-constrained-tabbing/**/*",
"src/hooks/use-instance-id/**/*",
"src/hooks/use-previous/**/*",
"src/utils/**/*"
]
}

0 comments on commit 409eef1

Please sign in to comment.