From f93fb748d18cf1808f642131b99c6ff71d038291 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 4 Apr 2024 17:59:19 +0200 Subject: [PATCH 1/6] Return useCallback and useMemo hooks --- packages/interactivity/src/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/interactivity/src/utils.js b/packages/interactivity/src/utils.js index 84e04803cea4f5..6adb93e167af06 100644 --- a/packages/interactivity/src/utils.js +++ b/packages/interactivity/src/utils.js @@ -192,7 +192,7 @@ export function useLayoutEffect( callback, inputs ) { * values in the list change (using `===`). */ export function useCallback( callback, inputs ) { - _useCallback( withScope( callback ), inputs ); + return _useCallback( withScope( callback ), inputs ); } /** @@ -209,7 +209,7 @@ export function useCallback( callback, inputs ) { * values in the list change (using `===`). */ export function useMemo( factory, inputs ) { - _useMemo( withScope( factory ), inputs ); + return _useMemo( withScope( factory ), inputs ); } // For wrapperless hydration. From e5b08008c1c6c7c9694fc80327ae616b05fd61ca Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 4 Apr 2024 17:59:57 +0200 Subject: [PATCH 2/6] changelog --- packages/interactivity/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/interactivity/CHANGELOG.md b/packages/interactivity/CHANGELOG.md index 7f4dd9296facc5..55247db99fbbcf 100644 --- a/packages/interactivity/CHANGELOG.md +++ b/packages/interactivity/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Bug Fixes + +- Hooks useMemo and useCallback should return a value. ([#59886](https://github.com/WordPress/gutenberg/pull/59886)) + ## 5.4.0 (2024-04-03) ## 5.3.0 (2024-03-21) From 93e99ae49d5df43deb1818ac10758e98ec1b9e81 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 4 Apr 2024 18:00:47 +0200 Subject: [PATCH 3/6] Fix PR number in changelog --- packages/interactivity/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/interactivity/CHANGELOG.md b/packages/interactivity/CHANGELOG.md index 55247db99fbbcf..e0b32cee128654 100644 --- a/packages/interactivity/CHANGELOG.md +++ b/packages/interactivity/CHANGELOG.md @@ -4,7 +4,7 @@ ### Bug Fixes -- Hooks useMemo and useCallback should return a value. ([#59886](https://github.com/WordPress/gutenberg/pull/59886)) +- Hooks useMemo and useCallback should return a value. ([#60474](https://github.com/WordPress/gutenberg/pull/60474)) ## 5.4.0 (2024-04-03) From cfe46a0a937924132118f571457b785b888f4123 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 4 Apr 2024 18:14:47 +0200 Subject: [PATCH 4/6] Update function descriptions --- packages/interactivity/src/utils.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/interactivity/src/utils.js b/packages/interactivity/src/utils.js index 6adb93e167af06..248d49256a11bc 100644 --- a/packages/interactivity/src/utils.js +++ b/packages/interactivity/src/utils.js @@ -186,9 +186,8 @@ export function useLayoutEffect( callback, inputs ) { * scope available so functions like `getElement()` and `getContext()` can be * used inside the passed callback. * - * @param {Function} callback Imperative function that can return a cleanup - * function. - * @param {any[]} inputs If present, effect will only activate if the + * @param {Function} callback Callback function. + * @param {any[]} inputs If present, the callback will only be updated if the * values in the list change (using `===`). */ export function useCallback( callback, inputs ) { @@ -203,9 +202,8 @@ export function useCallback( callback, inputs ) { * available so functions like `getElement()` and `getContext()` can be used * inside the passed factory function. * - * @param {Function} factory Imperative function that can return a cleanup - * function. - * @param {any[]} inputs If present, effect will only activate if the + * @param {Function} factory Factory function that returns that value for memoization. + * @param {any[]} inputs If present, the factory will only be run to recompute if the * values in the list change (using `===`). */ export function useMemo( factory, inputs ) { From f0ebfe39d23a6a755eb8977366653d5caff76e84 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 5 Apr 2024 09:41:28 +0200 Subject: [PATCH 5/6] Add return and fix/improve JSDoc types --- packages/interactivity/src/utils.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/interactivity/src/utils.js b/packages/interactivity/src/utils.js index 248d49256a11bc..acdcd1ad826015 100644 --- a/packages/interactivity/src/utils.js +++ b/packages/interactivity/src/utils.js @@ -186,9 +186,13 @@ export function useLayoutEffect( callback, inputs ) { * scope available so functions like `getElement()` and `getContext()` can be * used inside the passed callback. * - * @param {Function} callback Callback function. - * @param {any[]} inputs If present, the callback will only be updated if the - * values in the list change (using `===`). + * @template {Function} T The callback function type. + * + * @param {T} callback Callback function. + * @param {ReadonlyArray} inputs If present, the callback will only be updated if the + * values in the list change (using `===`). + * + * @return {T} The callback function. */ export function useCallback( callback, inputs ) { return _useCallback( withScope( callback ), inputs ); @@ -202,9 +206,13 @@ export function useCallback( callback, inputs ) { * available so functions like `getElement()` and `getContext()` can be used * inside the passed factory function. * - * @param {Function} factory Factory function that returns that value for memoization. - * @param {any[]} inputs If present, the factory will only be run to recompute if the - * values in the list change (using `===`). + * @template {unknown} T The momized value. + * + * @param {() => T} factory Factory function that returns that value for memoization. + * @param {ReadonlyArray} inputs If present, the factory will only be run to recompute if + * the values in the list change (using `===`). + * + * @return {T} The memoized value. */ export function useMemo( factory, inputs ) { return _useMemo( withScope( factory ), inputs ); From f0fc3a05d6421024c14e90f19bc7741afa605093 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 5 Apr 2024 09:47:53 +0200 Subject: [PATCH 6/6] Fix typo in JSDoc. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Greg Ziółkowski --- packages/interactivity/src/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/interactivity/src/utils.js b/packages/interactivity/src/utils.js index acdcd1ad826015..37a5f5eb6a97ba 100644 --- a/packages/interactivity/src/utils.js +++ b/packages/interactivity/src/utils.js @@ -206,7 +206,7 @@ export function useCallback( callback, inputs ) { * available so functions like `getElement()` and `getContext()` can be used * inside the passed factory function. * - * @template {unknown} T The momized value. + * @template {unknown} T The memoized value. * * @param {() => T} factory Factory function that returns that value for memoization. * @param {ReadonlyArray} inputs If present, the factory will only be run to recompute if