Skip to content

Commit

Permalink
Interactivity: Return useMemo and useCallback hooks (WordPress#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 <[email protected]>
Co-authored-by: gziolo <[email protected]>
  • Loading branch information
3 people authored and cbravobernal committed Apr 9, 2024
1 parent 95fda45 commit b9338e5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 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
30 changes: 18 additions & 12 deletions packages/interactivity/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,16 @@ export function useLayoutEffect( callback: Function, inputs: any[] ) {
* scope available so functions like `getElement()` and `getContext()` can be
* used inside the passed callback.
*
* @param callback Imperative function that can return a cleanup
* function.
* @param 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: Function, inputs: any[] ) {
_useCallback( withScope( callback ), inputs );
export function useCallback( callback, inputs ) {
return _useCallback( withScope( callback ), inputs );
}

/**
Expand All @@ -228,13 +231,16 @@ export function useCallback( callback: Function, inputs: any[] ) {
* available so functions like `getElement()` and `getContext()` can be used
* inside the passed factory function.
*
* @param factory Imperative function that can return a cleanup
* function.
* @param 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: Function, inputs: any[] ) {
_useMemo( withScope( factory ), inputs );
export function useMemo( factory, inputs ) {
return _useMemo( withScope( factory ), inputs );
}

/**
Expand Down

0 comments on commit b9338e5

Please sign in to comment.