-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
useSelect doesn't return the updated value if it is not an object. #16612
Comments
Ya, gutenberg/packages/data/src/components/use-select/index.js Lines 132 to 134 in a894b35
So the question then is:
I think the latter would be useful. In addition: We should also make sure tests cover whatever we decide. If the latter, the existing unit tests will need updated to cover testing the |
I'd go with the latter as well. We should have a shallow comparison helper that handles all data types. |
I probably will find some time to do that this week. |
Since it seems to generate a new array every time, strict equal fails, triggering a new component update. To avoid this, return undefined when there are no block validation errors anyway. Kind of related: WordPress/gutenberg#16612
Since it seems to generate a new array every time, strict equal fails, triggering a new component update. To avoid this, return undefined when there are no block validation errors anyway. Kind of related: WordPress/gutenberg#16612
Describe the bug
Following the documentation of useSelect hook to return a value from the store (custom or core) the updated value is only returned if the callback returns an object.
To reproduce
Try the following isolated. Notice that in the third example
getSelectedBlock()
is being returned as is.Doesn't update
const is_typing = useSelect(select => select("core/block-editor").isTyping());
Updates correctly
const is_typing = useSelect(select => ({ value: select("core/block-editor").isTyping() }));
Updates correctly
const selected = useSelect(select => select("core/block-editor").getSelectedBlock());
Version:
The text was updated successfully, but these errors were encountered: