-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interactivity: Return useMemo and useCallback hooks #60474
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +122 B (0%) Total Size: 1.73 MB
ℹ️ View Unchanged
|
It looks like some simple unit tests would fit here perfectly so folks don’t always need to open the browser to validate it. |
packages/interactivity/src/utils.js
Outdated
* 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSDoc misses now the @return
pragma for both updated functions.
I agree, but I don't think there's any set up for unit tests for interactivity. With these hooks that's something we'd have to figure out, it's usually not trivial to test hooks (at least with React). I could add another e2e test for hooks, there isn't one yet. |
Adding e2e test only to verify whether a function returns something is rather too much. It can be tested manually, too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢
Co-authored-by: Greg Ziółkowski <[email protected]>
Return a value from the useMemo and useCallback hooks. --------- Co-authored-by: sirreal <[email protected]> Co-authored-by: gziolo <[email protected]>
What?
Return a value from
useMemo
anduseCallback
hooks.Observed while reviewing #60149.
Why?
The
useCallback
anduseMemo
hooks are intended to be analogous to preact hooks and should return a value.Testing Instructions
Run this with a plugin with a
viewScriptModule
that uses these hooks, like this:Render some HTML like this:
You should see this logged to the console: