Skip to content

Commit

Permalink
Interactivity: Return useMemo and useCallback hooks (#60474)
Browse files Browse the repository at this point in the history
Return a value from the useMemo and useCallback hooks.

---------

Co-authored-by: sirreal <jonsurrell@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
  • Loading branch information
3 people committed Apr 5, 2024
1 parent f022ade commit fe96a16
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 4 additions & 0 deletions packages/interactivity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 16 additions & 10 deletions packages/interactivity/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown>} 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 );
}

/**
Expand All @@ -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<unknown>} 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.
Expand Down

0 comments on commit fe96a16

Please sign in to comment.