diff --git a/packages/interactivity/CHANGELOG.md b/packages/interactivity/CHANGELOG.md index 7f4dd9296facc5..e0b32cee128654 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. ([#60474](https://github.com/WordPress/gutenberg/pull/60474)) + ## 5.4.0 (2024-04-03) ## 5.3.0 (2024-03-21) diff --git a/packages/interactivity/src/utils.js b/packages/interactivity/src/utils.js index 84e04803cea4f5..37a5f5eb6a97ba 100644 --- a/packages/interactivity/src/utils.js +++ b/packages/interactivity/src/utils.js @@ -186,13 +186,16 @@ 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 - * 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 ) { - _useCallback( withScope( callback ), inputs ); + return _useCallback( withScope( callback ), inputs ); } /** @@ -203,13 +206,16 @@ 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 - * values in the list change (using `===`). + * @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 + * the values in the list change (using `===`). + * + * @return {T} The memoized value. */ export function useMemo( factory, inputs ) { - _useMemo( withScope( factory ), inputs ); + return _useMemo( withScope( factory ), inputs ); } // For wrapperless hydration.