-
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
Block Editor: Add hook: useNoRecursiveRenders #28428
Conversation
Originally introduced in #28405 to prevent Reusable Blocks from infinitely and fatally recurring, React hook `useNoRecursiveRenders` has a place in the block-editor package so that other block types susceptible to recursion can be fixed too.
Size Change: +42 B (0%) Total Size: 1.39 MB
ℹ️ View Unchanged
|
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.
Thank you for opening a follow-up ❤️
Tests work so we can ship I think 🚢
return result; | ||
} | ||
|
||
export default function useNoRecursiveRenders( uniqueId ) { |
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 comment with an example should help create README.md
once it gets promoted stable. In addition, it will make it easier to type the package with TS in the future.
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.
How's this? 1c3b036
I'm not familiar with our latest typing practice. Do you have a specific React type you recommend for the returned provider? For now I just used Function
.
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.
Yes, this is exactly what I meant 👍🏻
If you think it deserves an example, you can use the following syntax:
gutenberg/packages/plugins/src/components/plugin-area/index.js
Lines 38 to 50 in 1608a02
* @example | |
* <caption>ESNext</caption> | |
* ```js | |
* // Using ESNext syntax | |
* import { PluginArea } from '@wordpress/plugins'; | |
* | |
* const Layout = () => ( | |
* <div> | |
* Content of the page | |
* <PluginArea /> | |
* </div> | |
* ); | |
* ``` |
Description
Follows up on #28405.
Originally introduced in #28405 to prevent Reusable Blocks from infinitely and fatally recurring, React hook
useNoRecursiveRenders
has a place in theblock-editor
package so that other block types susceptible to recursion can be fixed too.This hook is marked as experimental, available under the name
__experimentalUseNoRecursiveRenders
.Along with the move, the hook was refactored to:
ref
(an allusion to theref
attribute of Reusable Blocks) becomesuniqueId
.Set
instead ofArray
to keep track of previously rendered blocks.How has this been tested?
This change should have no observable effects.
Types of changes
Refactor; new API
Checklist: